github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_openbsd_386.s (about)

     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  // System calls and other sys.stuff for 386, OpenBSD
     6  // /usr/src/sys/kern/syscalls.master for syscall numbers.
     7  //
     8  
     9  #include "go_asm.h"
    10  #include "go_tls.h"
    11  #include "textflag.h"
    12  
    13  #define	CLOCK_MONOTONIC	$3
    14  
    15  // Exit the entire program (like C exit)
    16  TEXT runtime·exit(SB),NOSPLIT,$-4
    17  	MOVL	$1, AX
    18  	INT	$0x80
    19  	MOVL	$0xf1, 0xf1		// crash
    20  	RET
    21  
    22  TEXT runtime·exit1(SB),NOSPLIT,$8
    23  	MOVL	$0, 0(SP)
    24  	MOVL	$0, 4(SP)		// arg 1 - notdead
    25  	MOVL	$302, AX		// sys___threxit
    26  	INT	$0x80
    27  	JAE	2(PC)
    28  	MOVL	$0xf1, 0xf1		// crash
    29  	RET
    30  
    31  TEXT runtime·open(SB),NOSPLIT,$-4
    32  	MOVL	$5, AX
    33  	INT	$0x80
    34  	JAE	2(PC)
    35  	MOVL	$-1, AX
    36  	MOVL	AX, ret+12(FP)
    37  	RET
    38  
    39  TEXT runtime·closefd(SB),NOSPLIT,$-4
    40  	MOVL	$6, AX
    41  	INT	$0x80
    42  	JAE	2(PC)
    43  	MOVL	$-1, AX
    44  	MOVL	AX, ret+4(FP)
    45  	RET
    46  
    47  TEXT runtime·read(SB),NOSPLIT,$-4
    48  	MOVL	$3, AX
    49  	INT	$0x80
    50  	JAE	2(PC)
    51  	MOVL	$-1, AX
    52  	MOVL	AX, ret+12(FP)
    53  	RET
    54  
    55  TEXT runtime·write(SB),NOSPLIT,$-4
    56  	MOVL	$4, AX			// sys_write
    57  	INT	$0x80
    58  	JAE	2(PC)
    59  	MOVL	$-1, AX
    60  	MOVL	AX, ret+12(FP)
    61  	RET
    62  
    63  TEXT runtime·usleep(SB),NOSPLIT,$24
    64  	MOVL	$0, DX
    65  	MOVL	usec+0(FP), AX
    66  	MOVL	$1000000, CX
    67  	DIVL	CX
    68  	MOVL	AX, 12(SP)		// tv_sec - l32
    69  	MOVL	$0, 16(SP)		// tv_sec - h32
    70  	MOVL	$1000, AX
    71  	MULL	DX
    72  	MOVL	AX, 20(SP)		// tv_nsec
    73  
    74  	MOVL	$0, 0(SP)
    75  	LEAL	12(SP), AX
    76  	MOVL	AX, 4(SP)		// arg 1 - rqtp
    77  	MOVL	$0, 8(SP)		// arg 2 - rmtp
    78  	MOVL	$91, AX			// sys_nanosleep
    79  	INT	$0x80
    80  	RET
    81  
    82  TEXT runtime·raise(SB),NOSPLIT,$12
    83  	MOVL	$299, AX		// sys_getthrid
    84  	INT	$0x80
    85  	MOVL	$0, 0(SP)
    86  	MOVL	AX, 4(SP)		// arg 1 - pid
    87  	MOVL	sig+0(FP), AX
    88  	MOVL	AX, 8(SP)		// arg 2 - signum
    89  	MOVL	$37, AX			// sys_kill
    90  	INT	$0x80
    91  	RET
    92  
    93  TEXT runtime·raiseproc(SB),NOSPLIT,$12
    94  	MOVL	$20, AX			// sys_getpid
    95  	INT	$0x80
    96  	MOVL	$0, 0(SP)
    97  	MOVL	AX, 4(SP)		// arg 1 - pid
    98  	MOVL	sig+0(FP), AX
    99  	MOVL	AX, 8(SP)		// arg 2 - signum
   100  	MOVL	$37, AX			// sys_kill
   101  	INT	$0x80
   102  	RET
   103  
   104  TEXT runtime·mmap(SB),NOSPLIT,$36
   105  	LEAL	addr+0(FP), SI
   106  	LEAL	4(SP), DI
   107  	CLD
   108  	MOVSL				// arg 1 - addr
   109  	MOVSL				// arg 2 - len
   110  	MOVSL				// arg 3 - prot
   111  	MOVSL				// arg 4 - flags
   112  	MOVSL				// arg 5 - fd
   113  	MOVL	$0, AX
   114  	STOSL				// arg 6 - pad
   115  	MOVSL				// arg 7 - offset
   116  	MOVL	$0, AX			// top 32 bits of file offset
   117  	STOSL
   118  	MOVL	$197, AX		// sys_mmap
   119  	INT	$0x80
   120  	MOVL	AX, ret+24(FP)
   121  	RET
   122  
   123  TEXT runtime·munmap(SB),NOSPLIT,$-4
   124  	MOVL	$73, AX			// sys_munmap
   125  	INT	$0x80
   126  	JAE	2(PC)
   127  	MOVL	$0xf1, 0xf1		// crash
   128  	RET
   129  
   130  TEXT runtime·madvise(SB),NOSPLIT,$-4
   131  	MOVL	$75, AX			// sys_madvise
   132  	INT	$0x80
   133  	JAE	2(PC)
   134  	MOVL	$0xf1, 0xf1		// crash
   135  	RET
   136  
   137  TEXT runtime·setitimer(SB),NOSPLIT,$-4
   138  	MOVL	$69, AX
   139  	INT	$0x80
   140  	RET
   141  
   142  // func now() (sec int64, nsec int32)
   143  TEXT time·now(SB), NOSPLIT, $32
   144  	LEAL	12(SP), BX
   145  	MOVL	$0, 4(SP)		// arg 1 - clock_id
   146  	MOVL	BX, 8(SP)		// arg 2 - tp
   147  	MOVL	$87, AX			// sys_clock_gettime
   148  	INT	$0x80
   149  
   150  	MOVL	12(SP), AX		// sec - l32
   151  	MOVL	AX, sec+0(FP)
   152  	MOVL	16(SP), AX		// sec - h32
   153  	MOVL	AX, sec+4(FP)
   154  
   155  	MOVL	20(SP), BX		// nsec
   156  	MOVL	BX, nsec+8(FP)
   157  	RET
   158  
   159  // int64 nanotime(void) so really
   160  // void nanotime(int64 *nsec)
   161  TEXT runtime·nanotime(SB),NOSPLIT,$32
   162  	LEAL	12(SP), BX
   163  	MOVL	CLOCK_MONOTONIC, 4(SP)	// arg 1 - clock_id
   164  	MOVL	BX, 8(SP)		// arg 2 - tp
   165  	MOVL	$87, AX			// sys_clock_gettime
   166  	INT	$0x80
   167  
   168  	MOVL    16(SP), CX		// sec - h32
   169  	IMULL   $1000000000, CX
   170  
   171  	MOVL    12(SP), AX		// sec - l32
   172  	MOVL    $1000000000, BX
   173  	MULL    BX			// result in dx:ax
   174  
   175  	MOVL	20(SP), BX		// nsec
   176  	ADDL	BX, AX
   177  	ADCL	CX, DX			// add high bits with carry
   178  
   179  	MOVL	AX, ret_lo+0(FP)
   180  	MOVL	DX, ret_hi+4(FP)
   181  	RET
   182  
   183  TEXT runtime·sigaction(SB),NOSPLIT,$-4
   184  	MOVL	$46, AX			// sys_sigaction
   185  	INT	$0x80
   186  	JAE	2(PC)
   187  	MOVL	$0xf1, 0xf1		// crash
   188  	RET
   189  
   190  TEXT runtime·sigprocmask(SB),NOSPLIT,$-4
   191  	MOVL	$48, AX			// sys_sigprocmask
   192  	INT	$0x80
   193  	JAE	2(PC)
   194  	MOVL	$0xf1, 0xf1		// crash
   195  	MOVL	AX, ret+8(FP)
   196  	RET
   197  
   198  TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   199  	MOVL	sig+4(FP), AX
   200  	MOVL	AX, 0(SP)
   201  	MOVL	info+8(FP), AX
   202  	MOVL	AX, 4(SP)
   203  	MOVL	ctx+12(FP), AX
   204  	MOVL	AX, 8(SP)
   205  	MOVL	fn+0(FP), AX
   206  	CALL	AX
   207  	RET
   208  
   209  TEXT runtime·sigtramp(SB),NOSPLIT,$12
   210  	MOVL	signo+0(FP), BX
   211  	MOVL	BX, 0(SP)
   212  	MOVL	info+4(FP), BX
   213  	MOVL	BX, 4(SP)
   214  	MOVL	context+8(FP), BX
   215  	MOVL	BX, 8(SP)
   216  	CALL	runtime·sigtrampgo(SB)
   217  
   218  	// call sigreturn
   219  	MOVL	context+8(FP), AX
   220  	MOVL	$0, 0(SP)		// syscall gap
   221  	MOVL	AX, 4(SP)		// arg 1 - sigcontext
   222  	MOVL	$103, AX		// sys_sigreturn
   223  	INT	$0x80
   224  	MOVL	$0xf1, 0xf1		// crash
   225  	RET
   226  
   227  // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
   228  TEXT runtime·tfork(SB),NOSPLIT,$12
   229  
   230  	// Copy mp, gp and fn from the parent stack onto the child stack.
   231  	MOVL	param+0(FP), AX
   232  	MOVL	8(AX), CX		// tf_stack
   233  	SUBL	$16, CX
   234  	MOVL	CX, 8(AX)
   235  	MOVL	mm+8(FP), SI
   236  	MOVL	SI, 0(CX)
   237  	MOVL	gg+12(FP), SI
   238  	MOVL	SI, 4(CX)
   239  	MOVL	fn+16(FP), SI
   240  	MOVL	SI, 8(CX)
   241  	MOVL	$1234, 12(CX)
   242  
   243  	MOVL	$0, 0(SP)		// syscall gap
   244  	MOVL	param+0(FP), AX
   245  	MOVL	AX, 4(SP)		// arg 1 - param
   246  	MOVL	psize+4(FP), AX
   247  	MOVL	AX, 8(SP)		// arg 2 - psize
   248  	MOVL	$8, AX			// sys___tfork
   249  	INT	$0x80
   250  
   251  	// Return if tfork syscall failed.
   252  	JCC	4(PC)
   253  	NEGL	AX
   254  	MOVL	AX, ret+20(FP)
   255  	RET
   256  
   257  	// In parent, return.
   258  	CMPL	AX, $0
   259  	JEQ	3(PC)
   260  	MOVL	AX, ret+20(FP)
   261  	RET
   262  
   263  	// Paranoia: check that SP is as we expect.
   264  	MOVL	12(SP), BP
   265  	CMPL	BP, $1234
   266  	JEQ	2(PC)
   267  	INT	$3
   268  
   269  	// Reload registers.
   270  	MOVL	0(SP), BX		// m
   271  	MOVL	4(SP), DX		// g
   272  	MOVL	8(SP), SI		// fn
   273  
   274  	// Set FS to point at m->tls.
   275  	LEAL	m_tls(BX), BP
   276  	PUSHAL				// save registers
   277  	PUSHL	BP
   278  	CALL	runtime·settls(SB)
   279  	POPL	AX
   280  	POPAL
   281  	
   282  	// Now segment is established.  Initialize m, g.
   283  	get_tls(AX)
   284  	MOVL	DX, g(AX)
   285  	MOVL	BX, g_m(DX)
   286  
   287  	CALL	runtime·stackcheck(SB)	// smashes AX, CX
   288  	MOVL	0(DX), DX		// paranoia; check they are not nil
   289  	MOVL	0(BX), BX
   290  
   291  	// More paranoia; check that stack splitting code works.
   292  	PUSHAL
   293  	CALL	runtime·emptyfunc(SB)
   294  	POPAL
   295  
   296  	// Call fn.
   297  	CALL	SI
   298  
   299  	CALL	runtime·exit1(SB)
   300  	MOVL	$0x1234, 0x1005
   301  	RET
   302  
   303  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   304  	MOVL	$288, AX		// sys_sigaltstack
   305  	MOVL	new+4(SP), BX
   306  	MOVL	old+8(SP), CX
   307  	INT	$0x80
   308  	CMPL	AX, $0xfffff001
   309  	JLS	2(PC)
   310  	INT	$3
   311  	RET
   312  
   313  TEXT runtime·setldt(SB),NOSPLIT,$4
   314  	// Under OpenBSD we set the GS base instead of messing with the LDT.
   315  	MOVL	tls0+4(FP), AX
   316  	MOVL	AX, 0(SP)
   317  	CALL	runtime·settls(SB)
   318  	RET
   319  
   320  TEXT runtime·settls(SB),NOSPLIT,$8
   321  	// adjust for ELF: wants to use -4(GS) for g
   322  	MOVL	tlsbase+0(FP), CX
   323  	ADDL	$4, CX
   324  	MOVL	$0, 0(SP)		// syscall gap
   325  	MOVL	CX, 4(SP)		// arg 1 - tcb
   326  	MOVL	$329, AX		// sys___set_tcb
   327  	INT	$0x80
   328  	JCC	2(PC)
   329  	MOVL	$0xf1, 0xf1		// crash
   330  	RET
   331  
   332  TEXT runtime·osyield(SB),NOSPLIT,$-4
   333  	MOVL	$298, AX		// sys_sched_yield
   334  	INT	$0x80
   335  	RET
   336  
   337  TEXT runtime·thrsleep(SB),NOSPLIT,$-4
   338  	MOVL	$94, AX			// sys___thrsleep
   339  	INT	$0x80
   340  	MOVL	AX, ret+20(FP)
   341  	RET
   342  
   343  TEXT runtime·thrwakeup(SB),NOSPLIT,$-4
   344  	MOVL	$301, AX		// sys___thrwakeup
   345  	INT	$0x80
   346  	MOVL	AX, ret+8(FP)
   347  	RET
   348  
   349  TEXT runtime·sysctl(SB),NOSPLIT,$28
   350  	LEAL	mib+0(FP), SI
   351  	LEAL	4(SP), DI
   352  	CLD
   353  	MOVSL				// arg 1 - name
   354  	MOVSL				// arg 2 - namelen
   355  	MOVSL				// arg 3 - oldp
   356  	MOVSL				// arg 4 - oldlenp
   357  	MOVSL				// arg 5 - newp
   358  	MOVSL				// arg 6 - newlen
   359  	MOVL	$202, AX		// sys___sysctl
   360  	INT	$0x80
   361  	JCC	4(PC)
   362  	NEGL	AX
   363  	MOVL	AX, ret+24(FP)
   364  	RET
   365  	MOVL	$0, AX
   366  	MOVL	AX, ret+24(FP)
   367  	RET
   368  
   369  // int32 runtime·kqueue(void);
   370  TEXT runtime·kqueue(SB),NOSPLIT,$0
   371  	MOVL	$269, AX
   372  	INT	$0x80
   373  	JAE	2(PC)
   374  	NEGL	AX
   375  	MOVL	AX, ret+0(FP)
   376  	RET
   377  
   378  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   379  TEXT runtime·kevent(SB),NOSPLIT,$0
   380  	MOVL	$72, AX			// sys_kevent
   381  	INT	$0x80
   382  	JAE	2(PC)
   383  	NEGL	AX
   384  	MOVL	AX, ret+24(FP)
   385  	RET
   386  
   387  // int32 runtime·closeonexec(int32 fd);
   388  TEXT runtime·closeonexec(SB),NOSPLIT,$32
   389  	MOVL	$92, AX			// sys_fcntl
   390  	// 0(SP) is where the caller PC would be; kernel skips it
   391  	MOVL	fd+0(FP), BX
   392  	MOVL	BX, 4(SP)	// fd
   393  	MOVL	$2, 8(SP)	// F_SETFD
   394  	MOVL	$1, 12(SP)	// FD_CLOEXEC
   395  	INT	$0x80
   396  	JAE	2(PC)
   397  	NEGL	AX
   398  	RET
   399  
   400  GLOBL runtime·tlsoffset(SB),NOPTR,$4