...
Run Format

Text file src/runtime/sys_darwin_arm64.s

Documentation: runtime

     1	// Copyright 2015 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 ARM64, Darwin
     6	// System calls are implemented in libSystem, this file contains
     7	// trampolines that convert from Go to C calling convention.
     8	
     9	#include "go_asm.h"
    10	#include "go_tls.h"
    11	#include "textflag.h"
    12	
    13	TEXT notok<>(SB),NOSPLIT,$0
    14		MOVD	$0, R8
    15		MOVD	R8, (R8)
    16		B	0(PC)
    17	
    18	TEXT runtime·open_trampoline(SB),NOSPLIT,$0
    19		MOVW	8(R0), R1	// arg 2 flags
    20		MOVW	12(R0), R2	// arg 3 mode
    21		MOVD	0(R0), R0	// arg 1 pathname
    22		BL libc_open(SB)
    23		RET
    24	
    25	TEXT runtime·close_trampoline(SB),NOSPLIT,$0
    26		MOVW	0(R0), R0	// arg 1 fd
    27		BL	libc_close(SB)
    28		RET
    29	
    30	TEXT runtime·write_trampoline(SB),NOSPLIT,$0
    31		MOVD	8(R0), R1	// arg 2 buf
    32		MOVW	16(R0), R2	// arg 3 count
    33		MOVW	0(R0), R0	// arg 1 fd
    34		BL	libc_write(SB)
    35		RET
    36	
    37	TEXT runtime·read_trampoline(SB),NOSPLIT,$0
    38		MOVD	8(R0), R1	// arg 2 buf
    39		MOVW	16(R0), R2	// arg 3 count
    40		MOVW	0(R0), R0	// arg 1 fd
    41		BL libc_read(SB)
    42		RET
    43	
    44	TEXT runtime·exit_trampoline(SB),NOSPLIT|NOFRAME,$0
    45		MOVW	0(R0), R0
    46		BL	libc_exit(SB)
    47		MOVD	$1234, R0
    48		MOVD	$1002, R1
    49		MOVD	R0, (R1)	// fail hard
    50	
    51	TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0
    52		MOVD	0(R0), R19	// signal
    53		BL	libc_getpid(SB)
    54		// arg 1 pid already in R0 from getpid
    55		MOVD	R19, R1	// arg 2 signal
    56		BL	libc_kill(SB)
    57		RET
    58	
    59	TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
    60		MOVD	R0, R19
    61		MOVD	0(R19), R0	// arg 1 addr
    62		MOVD	8(R19), R1	// arg 2 len
    63		MOVW	16(R19), R2	// arg 3 prot
    64		MOVW	20(R19), R3	// arg 4 flags
    65		MOVW	24(R19), R4	// arg 5 fd
    66		MOVW	28(R19), R5	// arg 6 off
    67		BL	libc_mmap(SB)
    68		MOVD	$0, R1
    69		MOVD	$-1, R2
    70		CMP	R0, R2
    71		BNE	ok
    72		BL libc_error(SB)
    73		MOVW	(R0), R1
    74		MOVD	$0, R0
    75	ok:
    76		MOVD	R0, 32(R19) // ret 1 p
    77		MOVD	R1, 40(R19)	// ret 2 err
    78		RET
    79	
    80	TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
    81		MOVD	8(R0), R1	// arg 2 len
    82		MOVD	0(R0), R0	// arg 1 addr
    83		BL	libc_munmap(SB)
    84		CMP $0, R0
    85		BEQ 2(PC)
    86		BL	notok<>(SB)
    87		RET
    88	
    89	TEXT runtime·madvise_trampoline(SB),NOSPLIT,$0
    90		MOVD	8(R0), R1	// arg 2 len
    91		MOVW	16(R0), R2	// arg 3 advice
    92		MOVD	0(R0), R0	// arg 1 addr
    93		BL	libc_madvise(SB)
    94		RET
    95	
    96	TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
    97		MOVD	8(R0), R1	// arg 2 new
    98		MOVD	16(R0), R2	// arg 3 old
    99		MOVW	0(R0), R0	// arg 1 which
   100		BL	libc_setitimer(SB)
   101		RET
   102	
   103	TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0
   104		// R0 already has *timeval
   105		MOVD	$0, R1 // no timezone needed
   106		BL	libc_gettimeofday(SB)
   107		RET
   108	
   109	GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
   110	
   111	TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$40
   112		MOVD	R0, R19
   113		BL	libc_mach_absolute_time(SB)
   114		MOVD	R0, 0(R19)
   115		MOVW	timebase<>+machTimebaseInfo_numer(SB), R20
   116		MOVD	$timebase<>+machTimebaseInfo_denom(SB), R21
   117		LDARW	(R21), R21	// atomic read
   118		CMP	$0, R21
   119		BNE	initialized
   120	
   121		SUB	$(machTimebaseInfo__size+15)/16*16, RSP
   122		MOVD	RSP, R0
   123		BL	libc_mach_timebase_info(SB)
   124		MOVW	machTimebaseInfo_numer(RSP), R20
   125		MOVW	machTimebaseInfo_denom(RSP), R21
   126		ADD	$(machTimebaseInfo__size+15)/16*16, RSP
   127	
   128		MOVW	R20, timebase<>+machTimebaseInfo_numer(SB)
   129		MOVD	$timebase<>+machTimebaseInfo_denom(SB), R22
   130		STLRW	R21, (R22)	// atomic write
   131	
   132	initialized:
   133		MOVW	R20, 8(R19)
   134		MOVW	R21, 12(R19)
   135		RET
   136	
   137	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   138		MOVW	sig+8(FP), R0
   139		MOVD	info+16(FP), R1
   140		MOVD	ctx+24(FP), R2
   141		MOVD	fn+0(FP), R11
   142		BL	(R11)
   143		RET
   144	
   145	TEXT runtime·sigtramp(SB),NOSPLIT,$0
   146		// Reserve space for callee-save registers and arguments.
   147		SUB	$(8*16), RSP
   148	
   149		// Save callee-save registers.
   150		MOVD	R19, (8*4)(RSP)
   151		MOVD	R20, (8*5)(RSP)
   152		MOVD	R21, (8*6)(RSP)
   153		MOVD	R22, (8*7)(RSP)
   154		MOVD	R23, (8*8)(RSP)
   155		MOVD	R24, (8*9)(RSP)
   156		MOVD	R25, (8*10)(RSP)
   157		MOVD	R26, (8*11)(RSP)
   158		MOVD	R27, (8*12)(RSP)
   159		MOVD	g, (8*13)(RSP)
   160		MOVD	R29, (8*14)(RSP)
   161	
   162		// Save arguments.
   163		MOVW	R0, (8*1)(RSP)	// sig
   164		MOVD	R1, (8*2)(RSP)	// info
   165		MOVD	R2, (8*3)(RSP)	// ctx
   166	
   167		// this might be called in external code context,
   168		// where g is not set.
   169		MOVB	runtime·iscgo(SB), R0
   170		CMP	$0, R0
   171		BEQ	2(PC)
   172		BL	runtime·load_g(SB)
   173	
   174		MOVD RSP, R6
   175		CMP	 $0, g
   176		BEQ	 nog
   177		// iOS always use the main stack to run the signal handler.
   178		// We need to switch to gsignal ourselves.
   179		MOVD	g_m(g), R11
   180		MOVD	m_gsignal(R11), R5
   181		MOVD	(g_stack+stack_hi)(R5), R6
   182	
   183	nog:
   184		// Restore arguments.
   185		MOVW	(8*1)(RSP), R0
   186		MOVD	(8*2)(RSP), R1
   187		MOVD	(8*3)(RSP), R2
   188	
   189		// Reserve space for args and the stack pointer on the
   190		// gsignal stack.
   191		SUB	$48, R6
   192		// Save stack pointer.
   193		MOVD	RSP, R4
   194		MOVD	R4, (8*4)(R6)
   195		// Switch to gsignal stack.
   196		MOVD	R6, RSP
   197	
   198		// Call sigtrampgo.
   199		MOVW	R0, (8*1)(RSP)
   200		MOVD	R1, (8*2)(RSP)
   201		MOVD	R2, (8*3)(RSP)
   202		MOVD	$runtime·sigtrampgo(SB), R11
   203		BL	(R11)
   204	
   205		// Switch to old stack.
   206		MOVD	(8*4)(RSP), R5
   207		MOVD	R5, RSP
   208	
   209		// Restore callee-save registers.
   210		MOVD	(8*4)(RSP), R19
   211		MOVD	(8*5)(RSP), R20
   212		MOVD	(8*6)(RSP), R21
   213		MOVD	(8*7)(RSP), R22
   214		MOVD	(8*8)(RSP), R23
   215		MOVD	(8*9)(RSP), R24
   216		MOVD	(8*10)(RSP), R25
   217		MOVD	(8*11)(RSP), R26
   218		MOVD	(8*12)(RSP), R27
   219		MOVD	(8*13)(RSP), g
   220		MOVD	(8*14)(RSP), R29
   221	
   222		ADD $(8*16), RSP
   223	
   224		RET
   225	
   226	TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   227		JMP	runtime·sigtramp(SB)
   228	
   229	TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
   230		MOVD	8(R0), R1	// arg 2 new
   231		MOVD	16(R0), R2	// arg 3 old
   232		MOVW	0(R0), R0	// arg 1 how
   233		BL	libc_pthread_sigmask(SB)
   234		CMP $0, R0
   235		BEQ	2(PC)
   236		BL	notok<>(SB)
   237		RET
   238	
   239	TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
   240		MOVD	8(R0), R1	// arg 2 new
   241		MOVD	16(R0), R2	// arg 3 old
   242		MOVW	0(R0), R0	// arg 1 how
   243		BL	libc_sigaction(SB)
   244		CMP	$0, R0
   245		BEQ	2(PC)
   246		BL	notok<>(SB)
   247		RET
   248	
   249	TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0
   250		MOVW	0(R0), R0	// arg 1 usec
   251		BL	libc_usleep(SB)
   252		RET
   253	
   254	TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0
   255		MOVW	8(R0), R1	// arg 2 miblen
   256		MOVD	16(R0), R2	// arg 3 out
   257		MOVD	24(R0), R3	// arg 4 size
   258		MOVD	32(R0), R4	// arg 5 dst
   259		MOVD	40(R0), R5	// arg 6 ndst
   260		MOVD	0(R0), R0	// arg 1 mib
   261		BL	libc_sysctl(SB)
   262		RET
   263	
   264	TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0
   265		BL	libc_kqueue(SB)
   266		RET
   267	
   268	TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
   269		MOVD	8(R0), R1	// arg 2 keventt
   270		MOVW	16(R0), R2	// arg 3 nch
   271		MOVD	24(R0), R3	// arg 4 ev
   272		MOVW	32(R0), R4	// arg 5 nev
   273		MOVD	40(R0), R5	// arg 6 ts
   274		MOVW	0(R0), R0	// arg 1 kq
   275		BL	libc_kevent(SB)
   276		MOVD	$-1, R2
   277		CMP	R0, R2
   278		BNE	ok
   279		BL libc_error(SB)
   280		MOVW	(R0), R0	// errno
   281		NEG	R0, R0	// caller wants it as a negative error code
   282	ok:
   283		RET
   284	
   285	TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
   286		MOVW	4(R0), R1	// arg 2 cmd
   287		MOVW	8(R0), R2	// arg 3 arg
   288		MOVW	0(R0), R0	// arg 1 fd
   289		BL	libc_fcntl(SB)
   290		RET
   291	
   292	// sigaltstack on iOS is not supported and will always
   293	// run the signal handler on the main stack, so our sigtramp has
   294	// to do the stack switch ourselves.
   295	TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
   296		MOVW	$43, R0
   297		BL	libc_exit(SB)
   298		RET
   299	
   300	// Thread related functions
   301	// Note: On darwin/arm64, the runtime always use runtime/cgo to
   302	// create threads, so all thread related functions will just exit with a
   303	// unique status.
   304	
   305	TEXT runtime·mstart_stub(SB),NOSPLIT,$0
   306		MOVW	$44, R0
   307		BL	libc_exit(SB)
   308		RET
   309	
   310	TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0
   311		MOVW	$45, R0
   312		BL	libc_exit(SB)
   313		RET
   314	
   315	TEXT runtime·pthread_attr_setstacksize_trampoline(SB),NOSPLIT,$0
   316		MOVW	$46, R0
   317		BL	libc_exit(SB)
   318		RET
   319	
   320	TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0
   321		MOVW	$47, R0
   322		BL	libc_exit(SB)
   323		RET
   324	
   325	TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
   326		MOVW	$48, R0
   327		BL	libc_exit(SB)
   328		RET
   329	
   330	TEXT runtime·raise_trampoline(SB),NOSPLIT,$0
   331		MOVW	0(R0), R0	// arg 1 sig
   332		BL	libc_raise(SB)
   333		RET
   334	
   335	TEXT runtime·pthread_mutex_init_trampoline(SB),NOSPLIT,$0
   336		MOVD	8(R0), R1	// arg 2 attr
   337		MOVD	0(R0), R0	// arg 1 mutex
   338		BL	libc_pthread_mutex_init(SB)
   339		RET
   340	
   341	TEXT runtime·pthread_mutex_lock_trampoline(SB),NOSPLIT,$0
   342		MOVD	0(R0), R0	// arg 1 mutex
   343		BL	libc_pthread_mutex_lock(SB)
   344		RET
   345	
   346	TEXT runtime·pthread_mutex_unlock_trampoline(SB),NOSPLIT,$0
   347		MOVD	0(R0), R0	// arg 1 mutex
   348		BL	libc_pthread_mutex_unlock(SB)
   349		RET
   350	
   351	TEXT runtime·pthread_cond_init_trampoline(SB),NOSPLIT,$0
   352		MOVD	8(R0), R1	// arg 2 attr
   353		MOVD	0(R0), R0	// arg 1 cond
   354		BL	libc_pthread_cond_init(SB)
   355		RET
   356	
   357	TEXT runtime·pthread_cond_wait_trampoline(SB),NOSPLIT,$0
   358		MOVD	8(R0), R1	// arg 2 mutex
   359		MOVD	0(R0), R0	// arg 1 cond
   360		BL	libc_pthread_cond_wait(SB)
   361		RET
   362	
   363	TEXT runtime·pthread_cond_timedwait_relative_np_trampoline(SB),NOSPLIT,$0
   364		MOVD	8(R0), R1	// arg 2 mutex
   365		MOVD	16(R0), R2	// arg 3 timeout
   366		MOVD	0(R0), R0	// arg 1 cond
   367		BL	libc_pthread_cond_timedwait_relative_np(SB)
   368		RET
   369	
   370	TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0
   371		MOVD	0(R0), R0	// arg 1 cond
   372		BL	libc_pthread_cond_signal(SB)
   373		RET
   374	

View as plain text