Text file src/runtime/asm_loong64.s

     1  // Copyright 2022 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 "funcdata.h"
     8  #include "textflag.h"
     9  
    10  #define	REGCTXT	R29
    11  
    12  TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
    13  	// R3 = stack; R4 = argc; R5 = argv
    14  
    15  	ADDV	$-24, R3
    16  	MOVW	R4, 8(R3) // argc
    17  	MOVV	R5, 16(R3) // argv
    18  
    19  	// create istack out of the given (operating system) stack.
    20  	// _cgo_init may update stackguard.
    21  	MOVV	$runtime·g0(SB), g
    22  	MOVV	$(-64*1024), R30
    23  	ADDV	R30, R3, R19
    24  	MOVV	R19, g_stackguard0(g)
    25  	MOVV	R19, g_stackguard1(g)
    26  	MOVV	R19, (g_stack+stack_lo)(g)
    27  	MOVV	R3, (g_stack+stack_hi)(g)
    28  
    29  	// if there is a _cgo_init, call it using the gcc ABI.
    30  	MOVV	_cgo_init(SB), R25
    31  	BEQ	R25, nocgo
    32  
    33  	MOVV	R0, R7	// arg 3: not used
    34  	MOVV	R0, R6	// arg 2: not used
    35  	MOVV	$setg_gcc<>(SB), R5	// arg 1: setg
    36  	MOVV	g, R4	// arg 0: G
    37  	JAL	(R25)
    38  
    39  nocgo:
    40  	// update stackguard after _cgo_init
    41  	MOVV	(g_stack+stack_lo)(g), R19
    42  	ADDV	$const_stackGuard, R19
    43  	MOVV	R19, g_stackguard0(g)
    44  	MOVV	R19, g_stackguard1(g)
    45  
    46  	// set the per-goroutine and per-mach "registers"
    47  	MOVV	$runtime·m0(SB), R19
    48  
    49  	// save m->g0 = g0
    50  	MOVV	g, m_g0(R19)
    51  	// save m0 to g0->m
    52  	MOVV	R19, g_m(g)
    53  
    54  	JAL	runtime·check(SB)
    55  
    56  	// args are already prepared
    57  	JAL	runtime·args(SB)
    58  	JAL	runtime·osinit(SB)
    59  	JAL	runtime·schedinit(SB)
    60  
    61  	// create a new goroutine to start program
    62  	MOVV	$runtime·mainPC(SB), R19		// entry
    63  	ADDV	$-16, R3
    64  	MOVV	R19, 8(R3)
    65  	MOVV	R0, 0(R3)
    66  	JAL	runtime·newproc(SB)
    67  	ADDV	$16, R3
    68  
    69  	// start this M
    70  	JAL	runtime·mstart(SB)
    71  
    72  	// Prevent dead-code elimination of debugCallV2, which is
    73  	// intended to be called by debuggers.
    74  	MOVV	$runtime·debugCallV2<ABIInternal>(SB), R0
    75  
    76  	MOVV	R0, 1(R0)
    77  	RET
    78  
    79  DATA	runtime·mainPC+0(SB)/8,$runtime·main<ABIInternal>(SB)
    80  GLOBL	runtime·mainPC(SB),RODATA,$8
    81  
    82  TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
    83  	BREAK
    84  	RET
    85  
    86  TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0
    87  	RET
    88  
    89  TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME,$0
    90  	JAL     runtime·mstart0(SB)
    91  	RET // not reached
    92  
    93  // func cputicks() int64
    94  TEXT runtime·cputicks<ABIInternal>(SB),NOSPLIT,$0-8
    95  	RDTIMED	R0, R4
    96  	RET
    97  
    98  /*
    99   *  go-routine
   100   */
   101  
   102  // void gogo(Gobuf*)
   103  // restore state from Gobuf; longjmp
   104  TEXT runtime·gogo(SB), NOSPLIT|NOFRAME, $0-8
   105  	MOVV	buf+0(FP), R4
   106  	MOVV	gobuf_g(R4), R5
   107  	MOVV	0(R5), R0	// make sure g != nil
   108  	JMP	gogo<>(SB)
   109  
   110  TEXT gogo<>(SB), NOSPLIT|NOFRAME, $0
   111  	MOVV	R5, g
   112  	JAL	runtime·save_g(SB)
   113  
   114  	MOVV	gobuf_sp(R4), R3
   115  	MOVV	gobuf_lr(R4), R1
   116  	MOVV	gobuf_ret(R4), R19
   117  	MOVV	gobuf_ctxt(R4), REGCTXT
   118  	MOVV	R0, gobuf_sp(R4)
   119  	MOVV	R0, gobuf_ret(R4)
   120  	MOVV	R0, gobuf_lr(R4)
   121  	MOVV	R0, gobuf_ctxt(R4)
   122  	MOVV	gobuf_pc(R4), R6
   123  	JMP	(R6)
   124  
   125  // void mcall(fn func(*g))
   126  // Switch to m->g0's stack, call fn(g).
   127  // Fn must never return. It should gogo(&g->sched)
   128  // to keep running g.
   129  TEXT runtime·mcall<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-8
   130  	MOVV	R4, REGCTXT
   131  	// Save caller state in g->sched
   132  	MOVV	R3, (g_sched+gobuf_sp)(g)
   133  	MOVV	R1, (g_sched+gobuf_pc)(g)
   134  	MOVV	R0, (g_sched+gobuf_lr)(g)
   135  
   136  	// Switch to m->g0 & its stack, call fn.
   137  	MOVV	g, R4		// arg = g
   138  	MOVV	g_m(g), R20
   139  	MOVV	m_g0(R20), g
   140  	JAL	runtime·save_g(SB)
   141  	BNE	g, R4, 2(PC)
   142  	JMP	runtime·badmcall(SB)
   143  	MOVV	0(REGCTXT), R20			// code pointer
   144  	MOVV	(g_sched+gobuf_sp)(g), R3	// sp = m->g0->sched.sp
   145  	ADDV	$-16, R3
   146  	MOVV	R4, 8(R3)
   147  	MOVV	R0, 0(R3)
   148  	JAL	(R20)
   149  	JMP	runtime·badmcall2(SB)
   150  
   151  // systemstack_switch is a dummy routine that systemstack leaves at the bottom
   152  // of the G stack. We need to distinguish the routine that
   153  // lives at the bottom of the G stack from the one that lives
   154  // at the top of the system stack because the one at the top of
   155  // the system stack terminates the stack walk (see topofstack()).
   156  TEXT runtime·systemstack_switch(SB), NOSPLIT, $0-0
   157  	UNDEF
   158  	JAL	(R1)	// make sure this function is not leaf
   159  	RET
   160  
   161  // func systemstack(fn func())
   162  TEXT runtime·systemstack(SB), NOSPLIT, $0-8
   163  	MOVV	fn+0(FP), R19	// R19 = fn
   164  	MOVV	R19, REGCTXT		// context
   165  	MOVV	g_m(g), R4	// R4 = m
   166  
   167  	MOVV	m_gsignal(R4), R5	// R5 = gsignal
   168  	BEQ	g, R5, noswitch
   169  
   170  	MOVV	m_g0(R4), R5	// R5 = g0
   171  	BEQ	g, R5, noswitch
   172  
   173  	MOVV	m_curg(R4), R6
   174  	BEQ	g, R6, switch
   175  
   176  	// Bad: g is not gsignal, not g0, not curg. What is it?
   177  	// Hide call from linker nosplit analysis.
   178  	MOVV	$runtime·badsystemstack(SB), R7
   179  	JAL	(R7)
   180  	JAL	runtime·abort(SB)
   181  
   182  switch:
   183  	// save our state in g->sched. Pretend to
   184  	// be systemstack_switch if the G stack is scanned.
   185  	JAL	gosave_systemstack_switch<>(SB)
   186  
   187  	// switch to g0
   188  	MOVV	R5, g
   189  	JAL	runtime·save_g(SB)
   190  	MOVV	(g_sched+gobuf_sp)(g), R19
   191  	MOVV	R19, R3
   192  
   193  	// call target function
   194  	MOVV	0(REGCTXT), R6	// code pointer
   195  	JAL	(R6)
   196  
   197  	// switch back to g
   198  	MOVV	g_m(g), R4
   199  	MOVV	m_curg(R4), g
   200  	JAL	runtime·save_g(SB)
   201  	MOVV	(g_sched+gobuf_sp)(g), R3
   202  	MOVV	R0, (g_sched+gobuf_sp)(g)
   203  	RET
   204  
   205  noswitch:
   206  	// already on m stack, just call directly
   207  	// Using a tail call here cleans up tracebacks since we won't stop
   208  	// at an intermediate systemstack.
   209  	MOVV	0(REGCTXT), R4	// code pointer
   210  	MOVV	0(R3), R1	// restore LR
   211  	ADDV	$8, R3
   212  	JMP	(R4)
   213  
   214  // func switchToCrashStack0(fn func())
   215  TEXT runtime·switchToCrashStack0<ABIInternal>(SB),NOSPLIT,$0-8
   216  	MOVV	R4, REGCTXT	// context register
   217  	MOVV	g_m(g), R5	// curm
   218  
   219  	// set g to gcrash
   220  	MOVV	$runtime·gcrash(SB), g	// g = &gcrash
   221  	JAL	runtime·save_g(SB)
   222  	MOVV	R5, g_m(g)	// g.m = curm
   223  	MOVV	g, m_g0(R5)	// curm.g0 = g
   224  
   225  	// switch to crashstack
   226  	MOVV	(g_stack+stack_hi)(g), R5
   227  	ADDV	$(-4*8), R5, R3
   228  
   229  	// call target function
   230  	MOVV	0(REGCTXT), R6
   231  	JAL	(R6)
   232  
   233  	// should never return
   234  	JAL	runtime·abort(SB)
   235  	UNDEF
   236  
   237  /*
   238   * support for morestack
   239   */
   240  
   241  // Called during function prolog when more stack is needed.
   242  // Caller has already loaded:
   243  // loong64: R31: LR
   244  //
   245  // The traceback routines see morestack on a g0 as being
   246  // the top of a stack (for example, morestack calling newstack
   247  // calling the scheduler calling newm calling gc), so we must
   248  // record an argument size. For that purpose, it has no arguments.
   249  TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
   250  	// Called from f.
   251  	// Set g->sched to context in f.
   252  	MOVV	R3, (g_sched+gobuf_sp)(g)
   253  	MOVV	R1, (g_sched+gobuf_pc)(g)
   254  	MOVV	R31, (g_sched+gobuf_lr)(g)
   255  	MOVV	REGCTXT, (g_sched+gobuf_ctxt)(g)
   256  
   257  	// Cannot grow scheduler stack (m->g0).
   258  	MOVV	g_m(g), R7
   259  	MOVV	m_g0(R7), R8
   260  	BNE	g, R8, 3(PC)
   261  	JAL	runtime·badmorestackg0(SB)
   262  	JAL	runtime·abort(SB)
   263  
   264  	// Cannot grow signal stack (m->gsignal).
   265  	MOVV	m_gsignal(R7), R8
   266  	BNE	g, R8, 3(PC)
   267  	JAL	runtime·badmorestackgsignal(SB)
   268  	JAL	runtime·abort(SB)
   269  
   270  	// Called from f.
   271  	// Set m->morebuf to f's caller.
   272  	MOVV	R31, (m_morebuf+gobuf_pc)(R7)	// f's caller's PC
   273  	MOVV	R3, (m_morebuf+gobuf_sp)(R7)	// f's caller's SP
   274  	MOVV	g, (m_morebuf+gobuf_g)(R7)
   275  
   276  	// Call newstack on m->g0's stack.
   277  	MOVV	m_g0(R7), g
   278  	JAL	runtime·save_g(SB)
   279  	MOVV	(g_sched+gobuf_sp)(g), R3
   280  	// Create a stack frame on g0 to call newstack.
   281  	MOVV	R0, -8(R3)	// Zero saved LR in frame
   282  	ADDV	$-8, R3
   283  	JAL	runtime·newstack(SB)
   284  
   285  	// Not reached, but make sure the return PC from the call to newstack
   286  	// is still in this function, and not the beginning of the next.
   287  	UNDEF
   288  
   289  TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
   290  	// Force SPWRITE. This function doesn't actually write SP,
   291  	// but it is called with a special calling convention where
   292  	// the caller doesn't save LR on stack but passes it as a
   293  	// register (R5), and the unwinder currently doesn't understand.
   294  	// Make it SPWRITE to stop unwinding. (See issue 54332)
   295  	MOVV    R3, R3
   296  
   297  	MOVV	R0, REGCTXT
   298  	JMP	runtime·morestack(SB)
   299  
   300  // reflectcall: call a function with the given argument list
   301  // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs).
   302  // we don't have variable-sized frames, so we use a small number
   303  // of constant-sized-frame functions to encode a few bits of size in the pc.
   304  // Caution: ugly multiline assembly macros in your future!
   305  
   306  #define DISPATCH(NAME,MAXSIZE)		\
   307  	MOVV	$MAXSIZE, R30;		\
   308  	SGTU	R19, R30, R30;		\
   309  	BNE	R30, 3(PC);			\
   310  	MOVV	$NAME(SB), R4;	\
   311  	JMP	(R4)
   312  // Note: can't just "BR NAME(SB)" - bad inlining results.
   313  
   314  TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48
   315  	MOVWU frameSize+32(FP), R19
   316  	DISPATCH(runtime·call32, 32)
   317  	DISPATCH(runtime·call64, 64)
   318  	DISPATCH(runtime·call128, 128)
   319  	DISPATCH(runtime·call256, 256)
   320  	DISPATCH(runtime·call512, 512)
   321  	DISPATCH(runtime·call1024, 1024)
   322  	DISPATCH(runtime·call2048, 2048)
   323  	DISPATCH(runtime·call4096, 4096)
   324  	DISPATCH(runtime·call8192, 8192)
   325  	DISPATCH(runtime·call16384, 16384)
   326  	DISPATCH(runtime·call32768, 32768)
   327  	DISPATCH(runtime·call65536, 65536)
   328  	DISPATCH(runtime·call131072, 131072)
   329  	DISPATCH(runtime·call262144, 262144)
   330  	DISPATCH(runtime·call524288, 524288)
   331  	DISPATCH(runtime·call1048576, 1048576)
   332  	DISPATCH(runtime·call2097152, 2097152)
   333  	DISPATCH(runtime·call4194304, 4194304)
   334  	DISPATCH(runtime·call8388608, 8388608)
   335  	DISPATCH(runtime·call16777216, 16777216)
   336  	DISPATCH(runtime·call33554432, 33554432)
   337  	DISPATCH(runtime·call67108864, 67108864)
   338  	DISPATCH(runtime·call134217728, 134217728)
   339  	DISPATCH(runtime·call268435456, 268435456)
   340  	DISPATCH(runtime·call536870912, 536870912)
   341  	DISPATCH(runtime·call1073741824, 1073741824)
   342  	MOVV	$runtime·badreflectcall(SB), R4
   343  	JMP	(R4)
   344  
   345  #define CALLFN(NAME,MAXSIZE)			\
   346  TEXT NAME(SB), WRAPPER, $MAXSIZE-48;		\
   347  	NO_LOCAL_POINTERS;			\
   348  	/* copy arguments to stack */		\
   349  	MOVV	arg+16(FP), R4;			\
   350  	MOVWU	argsize+24(FP), R5;			\
   351  	MOVV	R3, R12;				\
   352  	ADDV	$8, R12;			\
   353  	ADDV	R12, R5;				\
   354  	BEQ	R12, R5, 6(PC);				\
   355  	MOVBU	(R4), R6;			\
   356  	ADDV	$1, R4;			\
   357  	MOVBU	R6, (R12);			\
   358  	ADDV	$1, R12;			\
   359  	JMP	-5(PC);				\
   360  	/* set up argument registers */		\
   361  	MOVV	regArgs+40(FP), R25;		\
   362  	JAL	·unspillArgs(SB);		\
   363  	/* call function */			\
   364  	MOVV	f+8(FP), REGCTXT;			\
   365  	MOVV	(REGCTXT), R25;			\
   366  	PCDATA  $PCDATA_StackMapIndex, $0;	\
   367  	JAL	(R25);				\
   368  	/* copy return values back */		\
   369  	MOVV	regArgs+40(FP), R25;		\
   370  	JAL	·spillArgs(SB);		\
   371  	MOVV	argtype+0(FP), R7;		\
   372  	MOVV	arg+16(FP), R4;			\
   373  	MOVWU	n+24(FP), R5;			\
   374  	MOVWU	retoffset+28(FP), R6;		\
   375  	ADDV	$8, R3, R12;				\
   376  	ADDV	R6, R12; 			\
   377  	ADDV	R6, R4;				\
   378  	SUBVU	R6, R5;				\
   379  	JAL	callRet<>(SB);			\
   380  	RET
   381  
   382  // callRet copies return values back at the end of call*. This is a
   383  // separate function so it can allocate stack space for the arguments
   384  // to reflectcallmove. It does not follow the Go ABI; it expects its
   385  // arguments in registers.
   386  TEXT callRet<>(SB), NOSPLIT, $40-0
   387  	NO_LOCAL_POINTERS
   388  	MOVV	R7, 8(R3)
   389  	MOVV	R4, 16(R3)
   390  	MOVV	R12, 24(R3)
   391  	MOVV	R5, 32(R3)
   392  	MOVV	R25, 40(R3)
   393  	JAL	runtime·reflectcallmove(SB)
   394  	RET
   395  
   396  CALLFN(·call16, 16)
   397  CALLFN(·call32, 32)
   398  CALLFN(·call64, 64)
   399  CALLFN(·call128, 128)
   400  CALLFN(·call256, 256)
   401  CALLFN(·call512, 512)
   402  CALLFN(·call1024, 1024)
   403  CALLFN(·call2048, 2048)
   404  CALLFN(·call4096, 4096)
   405  CALLFN(·call8192, 8192)
   406  CALLFN(·call16384, 16384)
   407  CALLFN(·call32768, 32768)
   408  CALLFN(·call65536, 65536)
   409  CALLFN(·call131072, 131072)
   410  CALLFN(·call262144, 262144)
   411  CALLFN(·call524288, 524288)
   412  CALLFN(·call1048576, 1048576)
   413  CALLFN(·call2097152, 2097152)
   414  CALLFN(·call4194304, 4194304)
   415  CALLFN(·call8388608, 8388608)
   416  CALLFN(·call16777216, 16777216)
   417  CALLFN(·call33554432, 33554432)
   418  CALLFN(·call67108864, 67108864)
   419  CALLFN(·call134217728, 134217728)
   420  CALLFN(·call268435456, 268435456)
   421  CALLFN(·call536870912, 536870912)
   422  CALLFN(·call1073741824, 1073741824)
   423  
   424  TEXT runtime·procyield(SB),NOSPLIT,$0-0
   425  	RET
   426  
   427  // Save state of caller into g->sched.
   428  // but using fake PC from systemstack_switch.
   429  // Must only be called from functions with no locals ($0)
   430  // or else unwinding from systemstack_switch is incorrect.
   431  // Smashes R19.
   432  TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0
   433  	MOVV    $runtime·systemstack_switch(SB), R19
   434  	ADDV	$8, R19
   435  	MOVV	R19, (g_sched+gobuf_pc)(g)
   436  	MOVV	R3, (g_sched+gobuf_sp)(g)
   437  	MOVV	R0, (g_sched+gobuf_lr)(g)
   438  	MOVV	R0, (g_sched+gobuf_ret)(g)
   439  	// Assert ctxt is zero. See func save.
   440  	MOVV	(g_sched+gobuf_ctxt)(g), R19
   441  	BEQ	R19, 2(PC)
   442  	JAL	runtime·abort(SB)
   443  	RET
   444  
   445  // func asmcgocall(fn, arg unsafe.Pointer) int32
   446  // Call fn(arg) on the scheduler stack,
   447  // aligned appropriately for the gcc ABI.
   448  // See cgocall.go for more details.
   449  TEXT ·asmcgocall(SB),NOSPLIT,$0-20
   450  	MOVV	fn+0(FP), R25
   451  	MOVV	arg+8(FP), R4
   452  
   453  	MOVV	R3, R12	// save original stack pointer
   454  	MOVV	g, R13
   455  
   456  	// Figure out if we need to switch to m->g0 stack.
   457  	// We get called to create new OS threads too, and those
   458  	// come in on the m->g0 stack already.
   459  	MOVV	g_m(g), R5
   460  	MOVV	m_gsignal(R5), R6
   461  	BEQ	R6, g, g0
   462  	MOVV	m_g0(R5), R6
   463  	BEQ	R6, g, g0
   464  
   465  	JAL	gosave_systemstack_switch<>(SB)
   466  	MOVV	R6, g
   467  	JAL	runtime·save_g(SB)
   468  	MOVV	(g_sched+gobuf_sp)(g), R3
   469  
   470  	// Now on a scheduling stack (a pthread-created stack).
   471  g0:
   472  	// Save room for two of our pointers.
   473  	ADDV	$-16, R3
   474  	MOVV	R13, 0(R3)	// save old g on stack
   475  	MOVV	(g_stack+stack_hi)(R13), R13
   476  	SUBVU	R12, R13
   477  	MOVV	R13, 8(R3)	// save depth in old g stack (can't just save SP, as stack might be copied during a callback)
   478  	JAL	(R25)
   479  
   480  	// Restore g, stack pointer. R4 is return value.
   481  	MOVV	0(R3), g
   482  	JAL	runtime·save_g(SB)
   483  	MOVV	(g_stack+stack_hi)(g), R5
   484  	MOVV	8(R3), R6
   485  	SUBVU	R6, R5
   486  	MOVV	R5, R3
   487  
   488  	MOVW	R4, ret+16(FP)
   489  	RET
   490  
   491  // func cgocallback(fn, frame unsafe.Pointer, ctxt uintptr)
   492  // See cgocall.go for more details.
   493  TEXT ·cgocallback(SB),NOSPLIT,$24-24
   494  	NO_LOCAL_POINTERS
   495  
   496  	// Skip cgocallbackg, just dropm when fn is nil, and frame is the saved g.
   497  	// It is used to dropm while thread is exiting.
   498  	MOVV    fn+0(FP), R5
   499  	BNE	R5, loadg
   500  	// Restore the g from frame.
   501  	MOVV    frame+8(FP), g
   502  	JMP	dropm
   503  
   504  loadg:
   505  	// Load m and g from thread-local storage.
   506  	MOVB	runtime·iscgo(SB), R19
   507  	BEQ	R19, nocgo
   508  	JAL	runtime·load_g(SB)
   509  nocgo:
   510  
   511  	// If g is nil, Go did not create the current thread,
   512  	// or if this thread never called into Go on pthread platforms.
   513  	// Call needm to obtain one for temporary use.
   514  	// In this case, we're running on the thread stack, so there's
   515  	// lots of space, but the linker doesn't know. Hide the call from
   516  	// the linker analysis by using an indirect call.
   517  	BEQ	g, needm
   518  
   519  	MOVV	g_m(g), R12
   520  	MOVV	R12, savedm-8(SP)
   521  	JMP	havem
   522  
   523  needm:
   524  	MOVV	g, savedm-8(SP) // g is zero, so is m.
   525  	MOVV	$runtime·needAndBindM(SB), R4
   526  	JAL	(R4)
   527  
   528  	// Set m->sched.sp = SP, so that if a panic happens
   529  	// during the function we are about to execute, it will
   530  	// have a valid SP to run on the g0 stack.
   531  	// The next few lines (after the havem label)
   532  	// will save this SP onto the stack and then write
   533  	// the same SP back to m->sched.sp. That seems redundant,
   534  	// but if an unrecovered panic happens, unwindm will
   535  	// restore the g->sched.sp from the stack location
   536  	// and then systemstack will try to use it. If we don't set it here,
   537  	// that restored SP will be uninitialized (typically 0) and
   538  	// will not be usable.
   539  	MOVV	g_m(g), R12
   540  	MOVV	m_g0(R12), R19
   541  	MOVV	R3, (g_sched+gobuf_sp)(R19)
   542  
   543  havem:
   544  	// Now there's a valid m, and we're running on its m->g0.
   545  	// Save current m->g0->sched.sp on stack and then set it to SP.
   546  	// Save current sp in m->g0->sched.sp in preparation for
   547  	// switch back to m->curg stack.
   548  	// NOTE: unwindm knows that the saved g->sched.sp is at 8(R29) aka savedsp-16(SP).
   549  	MOVV	m_g0(R12), R19
   550  	MOVV	(g_sched+gobuf_sp)(R19), R13
   551  	MOVV	R13, savedsp-24(SP) // must match frame size
   552  	MOVV	R3, (g_sched+gobuf_sp)(R19)
   553  
   554  	// Switch to m->curg stack and call runtime.cgocallbackg.
   555  	// Because we are taking over the execution of m->curg
   556  	// but *not* resuming what had been running, we need to
   557  	// save that information (m->curg->sched) so we can restore it.
   558  	// We can restore m->curg->sched.sp easily, because calling
   559  	// runtime.cgocallbackg leaves SP unchanged upon return.
   560  	// To save m->curg->sched.pc, we push it onto the stack.
   561  	// This has the added benefit that it looks to the traceback
   562  	// routine like cgocallbackg is going to return to that
   563  	// PC (because the frame we allocate below has the same
   564  	// size as cgocallback_gofunc's frame declared above)
   565  	// so that the traceback will seamlessly trace back into
   566  	// the earlier calls.
   567  	MOVV	m_curg(R12), g
   568  	JAL	runtime·save_g(SB)
   569  	MOVV	(g_sched+gobuf_sp)(g), R13 // prepare stack as R13
   570  	MOVV	(g_sched+gobuf_pc)(g), R4
   571  	MOVV	R4, -(24+8)(R13) // "saved LR"; must match frame size
   572  	MOVV    fn+0(FP), R5
   573  	MOVV    frame+8(FP), R6
   574  	MOVV    ctxt+16(FP), R7
   575  	MOVV	$-(24+8)(R13), R3
   576  	MOVV    R5, 8(R3)
   577  	MOVV    R6, 16(R3)
   578  	MOVV    R7, 24(R3)
   579  	JAL	runtime·cgocallbackg(SB)
   580  
   581  	// Restore g->sched (== m->curg->sched) from saved values.
   582  	MOVV	0(R3), R4
   583  	MOVV	R4, (g_sched+gobuf_pc)(g)
   584  	MOVV	$(24+8)(R3), R13 // must match frame size
   585  	MOVV	R13, (g_sched+gobuf_sp)(g)
   586  
   587  	// Switch back to m->g0's stack and restore m->g0->sched.sp.
   588  	// (Unlike m->curg, the g0 goroutine never uses sched.pc,
   589  	// so we do not have to restore it.)
   590  	MOVV	g_m(g), R12
   591  	MOVV	m_g0(R12), g
   592  	JAL	runtime·save_g(SB)
   593  	MOVV	(g_sched+gobuf_sp)(g), R3
   594  	MOVV	savedsp-24(SP), R13 // must match frame size
   595  	MOVV	R13, (g_sched+gobuf_sp)(g)
   596  
   597  	// If the m on entry was nil, we called needm above to borrow an m,
   598  	// 1. for the duration of the call on non-pthread platforms,
   599  	// 2. or the duration of the C thread alive on pthread platforms.
   600  	// If the m on entry wasn't nil,
   601  	// 1. the thread might be a Go thread,
   602  	// 2. or it wasn't the first call from a C thread on pthread platforms,
   603  	//    since then we skip dropm to resue the m in the first call.
   604  	MOVV	savedm-8(SP), R12
   605  	BNE	R12, droppedm
   606  
   607  	// Skip dropm to reuse it in the next call, when a pthread key has been created.
   608  	MOVV	_cgo_pthread_key_created(SB), R12
   609  	// It means cgo is disabled when _cgo_pthread_key_created is a nil pointer, need dropm.
   610  	BEQ	R12, dropm
   611  	MOVV    (R12), R12
   612  	BNE	R12, droppedm
   613  
   614  dropm:
   615  	MOVV	$runtime·dropm(SB), R4
   616  	JAL	(R4)
   617  droppedm:
   618  
   619  	// Done!
   620  	RET
   621  
   622  // void setg(G*); set g. for use by needm.
   623  TEXT runtime·setg(SB), NOSPLIT, $0-8
   624  	MOVV	gg+0(FP), g
   625  	// This only happens if iscgo, so jump straight to save_g
   626  	JAL	runtime·save_g(SB)
   627  	RET
   628  
   629  // void setg_gcc(G*); set g called from gcc with g in R19
   630  TEXT setg_gcc<>(SB),NOSPLIT,$0-0
   631  	MOVV	R19, g
   632  	JAL	runtime·save_g(SB)
   633  	RET
   634  
   635  TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
   636  	MOVW	(R0), R0
   637  	UNDEF
   638  
   639  // AES hashing not implemented for loong64
   640  TEXT runtime·memhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-32
   641  	JMP	runtime·memhashFallback<ABIInternal>(SB)
   642  TEXT runtime·strhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
   643  	JMP	runtime·strhashFallback<ABIInternal>(SB)
   644  TEXT runtime·memhash32<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
   645  	JMP	runtime·memhash32Fallback<ABIInternal>(SB)
   646  TEXT runtime·memhash64<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
   647  	JMP	runtime·memhash64Fallback<ABIInternal>(SB)
   648  
   649  TEXT runtime·return0(SB), NOSPLIT, $0
   650  	MOVW	$0, R19
   651  	RET
   652  
   653  // Called from cgo wrappers, this function returns g->m->curg.stack.hi.
   654  // Must obey the gcc calling convention.
   655  TEXT _cgo_topofstack(SB),NOSPLIT,$16
   656  	// g (R22) and REGTMP (R30)  might be clobbered by load_g. They
   657  	// are callee-save in the gcc calling convention, so save them.
   658  	MOVV	R30, savedREGTMP-16(SP)
   659  	MOVV	g, savedG-8(SP)
   660  
   661  	JAL	runtime·load_g(SB)
   662  	MOVV	g_m(g), R19
   663  	MOVV	m_curg(R19), R19
   664  	MOVV	(g_stack+stack_hi)(R19), R4 // return value in R4
   665  
   666  	MOVV	savedG-8(SP), g
   667  	MOVV	savedREGTMP-16(SP), R30
   668  	RET
   669  
   670  // The top-most function running on a goroutine
   671  // returns to goexit+PCQuantum.
   672  TEXT runtime·goexit(SB),NOSPLIT|NOFRAME|TOPFRAME,$0-0
   673  	NOOP
   674  	JAL	runtime·goexit1(SB)	// does not return
   675  	// traceback from goexit1 must hit code range of goexit
   676  	NOOP
   677  
   678  // This is called from .init_array and follows the platform, not Go, ABI.
   679  TEXT runtime·addmoduledata(SB),NOSPLIT,$0-0
   680  	ADDV	$-0x10, R3
   681  	MOVV	R30, 8(R3) // The access to global variables below implicitly uses R30, which is callee-save
   682  	MOVV	runtime·lastmoduledatap(SB), R12
   683  	MOVV	R4, moduledata_next(R12)
   684  	MOVV	R4, runtime·lastmoduledatap(SB)
   685  	MOVV	8(R3), R30
   686  	ADDV	$0x10, R3
   687  	RET
   688  
   689  TEXT ·checkASM(SB),NOSPLIT,$0-1
   690  	MOVW	$1, R19
   691  	MOVB	R19, ret+0(FP)
   692  	RET
   693  
   694  // spillArgs stores return values from registers to a *internal/abi.RegArgs in R25.
   695  TEXT ·spillArgs(SB),NOSPLIT,$0-0
   696  	MOVV	R4, (0*8)(R25)
   697  	MOVV	R5, (1*8)(R25)
   698  	MOVV	R6, (2*8)(R25)
   699  	MOVV	R7, (3*8)(R25)
   700  	MOVV	R8, (4*8)(R25)
   701  	MOVV	R9, (5*8)(R25)
   702  	MOVV	R10, (6*8)(R25)
   703  	MOVV	R11, (7*8)(R25)
   704  	MOVV	R12, (8*8)(R25)
   705  	MOVV	R13, (9*8)(R25)
   706  	MOVV	R14, (10*8)(R25)
   707  	MOVV	R15, (11*8)(R25)
   708  	MOVV	R16, (12*8)(R25)
   709  	MOVV	R17, (13*8)(R25)
   710  	MOVV	R18, (14*8)(R25)
   711  	MOVV	R19, (15*8)(R25)
   712  	MOVD	F0, (16*8)(R25)
   713  	MOVD	F1, (17*8)(R25)
   714  	MOVD	F2, (18*8)(R25)
   715  	MOVD	F3, (19*8)(R25)
   716  	MOVD	F4, (20*8)(R25)
   717  	MOVD	F5, (21*8)(R25)
   718  	MOVD	F6, (22*8)(R25)
   719  	MOVD	F7, (23*8)(R25)
   720  	MOVD	F8, (24*8)(R25)
   721  	MOVD	F9, (25*8)(R25)
   722  	MOVD	F10, (26*8)(R25)
   723  	MOVD	F11, (27*8)(R25)
   724  	MOVD	F12, (28*8)(R25)
   725  	MOVD	F13, (29*8)(R25)
   726  	MOVD	F14, (30*8)(R25)
   727  	MOVD	F15, (31*8)(R25)
   728  	RET
   729  
   730  // unspillArgs loads args into registers from a *internal/abi.RegArgs in R25.
   731  TEXT ·unspillArgs(SB),NOSPLIT,$0-0
   732  	MOVV	(0*8)(R25), R4
   733  	MOVV	(1*8)(R25), R5
   734  	MOVV	(2*8)(R25), R6
   735  	MOVV	(3*8)(R25), R7
   736  	MOVV	(4*8)(R25), R8
   737  	MOVV	(5*8)(R25), R9
   738  	MOVV	(6*8)(R25), R10
   739  	MOVV	(7*8)(R25), R11
   740  	MOVV	(8*8)(R25), R12
   741  	MOVV	(9*8)(R25), R13
   742  	MOVV	(10*8)(R25), R14
   743  	MOVV	(11*8)(R25), R15
   744  	MOVV	(12*8)(R25), R16
   745  	MOVV	(13*8)(R25), R17
   746  	MOVV	(14*8)(R25), R18
   747  	MOVV	(15*8)(R25), R19
   748  	MOVD	(16*8)(R25), F0
   749  	MOVD	(17*8)(R25), F1
   750  	MOVD	(18*8)(R25), F2
   751  	MOVD	(19*8)(R25), F3
   752  	MOVD	(20*8)(R25), F4
   753  	MOVD	(21*8)(R25), F5
   754  	MOVD	(22*8)(R25), F6
   755  	MOVD	(23*8)(R25), F7
   756  	MOVD	(24*8)(R25), F8
   757  	MOVD	(25*8)(R25), F9
   758  	MOVD	(26*8)(R25), F10
   759  	MOVD	(27*8)(R25), F11
   760  	MOVD	(28*8)(R25), F12
   761  	MOVD	(29*8)(R25), F13
   762  	MOVD	(30*8)(R25), F14
   763  	MOVD	(31*8)(R25), F15
   764  	RET
   765  
   766  // gcWriteBarrier informs the GC about heap pointer writes.
   767  //
   768  // gcWriteBarrier does NOT follow the Go ABI. It accepts the
   769  // number of bytes of buffer needed in R29, and returns a pointer
   770  // to the buffer space in R29.
   771  // It clobbers R30 (the linker temp register).
   772  // The act of CALLing gcWriteBarrier will clobber R1 (LR).
   773  // It does not clobber any other general-purpose registers,
   774  // but may clobber others (e.g., floating point registers).
   775  TEXT gcWriteBarrier<>(SB),NOSPLIT,$216
   776  	// Save the registers clobbered by the fast path.
   777  	MOVV	R19, 208(R3)
   778  	MOVV	R13, 216(R3)
   779  retry:
   780  	MOVV	g_m(g), R19
   781  	MOVV	m_p(R19), R19
   782  	MOVV	(p_wbBuf+wbBuf_next)(R19), R13
   783  	MOVV	(p_wbBuf+wbBuf_end)(R19), R30 // R30 is linker temp register
   784  	// Increment wbBuf.next position.
   785  	ADDV	R29, R13
   786  	// Is the buffer full?
   787  	BLTU	R30, R13, flush
   788  	// Commit to the larger buffer.
   789  	MOVV	R13, (p_wbBuf+wbBuf_next)(R19)
   790  	// Make return value (the original next position)
   791  	SUBV	R29, R13, R29
   792  	// Restore registers.
   793  	MOVV	208(R3), R19
   794  	MOVV	216(R3), R13
   795  	RET
   796  
   797  flush:
   798  	// Save all general purpose registers since these could be
   799  	// clobbered by wbBufFlush and were not saved by the caller.
   800  	MOVV	R27, 8(R3)
   801  	MOVV	R28, 16(R3)
   802  	// R1 is LR, which was saved by the prologue.
   803  	MOVV	R2, 24(R3)
   804  	// R3 is SP.
   805  	MOVV	R4, 32(R3)
   806  	MOVV	R5, 40(R3)
   807  	MOVV	R6, 48(R3)
   808  	MOVV	R7, 56(R3)
   809  	MOVV	R8, 64(R3)
   810  	MOVV	R9, 72(R3)
   811  	MOVV	R10, 80(R3)
   812  	MOVV	R11, 88(R3)
   813  	MOVV	R12, 96(R3)
   814  	// R13 already saved
   815  	MOVV	R14, 104(R3)
   816  	MOVV	R15, 112(R3)
   817  	MOVV	R16, 120(R3)
   818  	MOVV	R17, 128(R3)
   819  	MOVV	R18, 136(R3)
   820  	// R19 already saved
   821  	MOVV	R20, 144(R3)
   822  	MOVV	R21, 152(R3)
   823  	// R22 is g.
   824  	MOVV	R23, 160(R3)
   825  	MOVV	R24, 168(R3)
   826  	MOVV	R25, 176(R3)
   827  	MOVV	R26, 184(R3)
   828  	// R27 already saved
   829  	// R28 already saved.
   830  	MOVV	R29, 192(R3)
   831  	// R30 is tmp register.
   832  	MOVV	R31, 200(R3)
   833  
   834  	CALL	runtime·wbBufFlush(SB)
   835  
   836  	MOVV	8(R3), R27
   837  	MOVV	16(R3), R28
   838  	MOVV	24(R3), R2
   839  	MOVV	32(R3), R4
   840  	MOVV	40(R3), R5
   841  	MOVV	48(R3), R6
   842  	MOVV	56(R3), R7
   843  	MOVV	64(R3), R8
   844  	MOVV	72(R3), R9
   845  	MOVV	80(R3), R10
   846  	MOVV	88(R3), R11
   847  	MOVV	96(R3), R12
   848  	MOVV	104(R3), R14
   849  	MOVV	112(R3), R15
   850  	MOVV	120(R3), R16
   851  	MOVV	128(R3), R17
   852  	MOVV	136(R3), R18
   853  	MOVV	144(R3), R20
   854  	MOVV	152(R3), R21
   855  	MOVV	160(R3), R23
   856  	MOVV	168(R3), R24
   857  	MOVV	176(R3), R25
   858  	MOVV	184(R3), R26
   859  	MOVV	192(R3), R29
   860  	MOVV	200(R3), R31
   861  	JMP	retry
   862  
   863  TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0
   864  	MOVV	$8, R29
   865  	JMP	gcWriteBarrier<>(SB)
   866  TEXT runtime·gcWriteBarrier2<ABIInternal>(SB),NOSPLIT,$0
   867  	MOVV	$16, R29
   868  	JMP	gcWriteBarrier<>(SB)
   869  TEXT runtime·gcWriteBarrier3<ABIInternal>(SB),NOSPLIT,$0
   870  	MOVV	$24, R29
   871  	JMP	gcWriteBarrier<>(SB)
   872  TEXT runtime·gcWriteBarrier4<ABIInternal>(SB),NOSPLIT,$0
   873  	MOVV	$32, R29
   874  	JMP	gcWriteBarrier<>(SB)
   875  TEXT runtime·gcWriteBarrier5<ABIInternal>(SB),NOSPLIT,$0
   876  	MOVV	$40, R29
   877  	JMP	gcWriteBarrier<>(SB)
   878  TEXT runtime·gcWriteBarrier6<ABIInternal>(SB),NOSPLIT,$0
   879  	MOVV	$48, R29
   880  	JMP	gcWriteBarrier<>(SB)
   881  TEXT runtime·gcWriteBarrier7<ABIInternal>(SB),NOSPLIT,$0
   882  	MOVV	$56, R29
   883  	JMP	gcWriteBarrier<>(SB)
   884  TEXT runtime·gcWriteBarrier8<ABIInternal>(SB),NOSPLIT,$0
   885  	MOVV	$64, R29
   886  	JMP	gcWriteBarrier<>(SB)
   887  
   888  DATA	debugCallFrameTooLarge<>+0x00(SB)/20, $"call frame too large"
   889  GLOBL	debugCallFrameTooLarge<>(SB), RODATA, $20	// Size duplicated below
   890  
   891  // debugCallV2 is the entry point for debugger-injected function
   892  // calls on running goroutines. It informs the runtime that a
   893  // debug call has been injected and creates a call frame for the
   894  // debugger to fill in.
   895  //
   896  // To inject a function call, a debugger should:
   897  // 1. Check that the goroutine is in state _Grunning and that
   898  //    there are at least 280 bytes free on the stack.
   899  // 2. Set SP as SP-8.
   900  // 3. Store the current LR in (SP) (using the SP after step 2).
   901  // 4. Store the current PC in the LR register.
   902  // 5. Write the desired argument frame size at SP-8
   903  // 6. Save all machine registers so they can be restored later by the debugger.
   904  // 7. Set the PC to debugCallV2 and resume execution.
   905  //
   906  // If the goroutine is in state _Grunnable, then it's not generally
   907  // safe to inject a call because it may return out via other runtime
   908  // operations. Instead, the debugger should unwind the stack to find
   909  // the return to non-runtime code, add a temporary breakpoint there,
   910  // and inject the call once that breakpoint is hit.
   911  //
   912  // If the goroutine is in any other state, it's not safe to inject a call.
   913  //
   914  // This function communicates back to the debugger by setting R19 and
   915  // invoking BREAK to raise a breakpoint signal. Note that the signal PC of
   916  // the signal triggered by the BREAK instruction is the PC where the signal
   917  // is trapped, not the next PC, so to resume execution, the debugger needs
   918  // to set the signal PC to PC+4. See the comments in the implementation for
   919  // the protocol the debugger is expected to follow. InjectDebugCall in the
   920  // runtime tests demonstrates this protocol.
   921  //
   922  // The debugger must ensure that any pointers passed to the function
   923  // obey escape analysis requirements. Specifically, it must not pass
   924  // a stack pointer to an escaping argument. debugCallV2 cannot check
   925  // this invariant.
   926  //
   927  // This is ABIInternal because Go code injects its PC directly into new
   928  // goroutine stacks.
   929  TEXT runtime·debugCallV2<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-0
   930  	MOVV    R1, -272(R3)
   931  	ADDV    $-272, R3
   932  
   933  	// We can't do anything that might clobber any of these
   934  	// registers before this.
   935  	MOVV    R2, (4*8)(R3)
   936  	MOVV    R4, (5*8)(R3)
   937  	MOVV    R5, (6*8)(R3)
   938  	MOVV    R6, (7*8)(R3)
   939  	MOVV    R7, (8*8)(R3)
   940  	MOVV    R8, (9*8)(R3)
   941  	MOVV    R9, (10*8)(R3)
   942  	MOVV    R10, (11*8)(R3)
   943  	MOVV    R11, (12*8)(R3)
   944  	MOVV    R12, (13*8)(R3)
   945  	MOVV    R13, (14*8)(R3)
   946  	MOVV    R14, (15*8)(R3)
   947  	MOVV    R15, (16*8)(R3)
   948  	MOVV    R16, (17*8)(R3)
   949  	MOVV    R17, (18*8)(R3)
   950  	MOVV    R18, (19*8)(R3)
   951  	MOVV    R19, (20*8)(R3)
   952  	MOVV    R20, (21*8)(R3)
   953  	MOVV    R21, (22*8)(R3)
   954  	MOVV    g, (23*8)(R3)
   955  	MOVV    R23, (24*8)(R3)
   956  	MOVV    R24, (25*8)(R3)
   957  	MOVV    R25, (26*8)(R3)
   958  	MOVV    R26, (27*8)(R3)
   959  	MOVV    R27, (28*8)(R3)
   960  	MOVV    R28, (29*8)(R3)
   961  	MOVV    R29, (30*8)(R3)
   962  	MOVV    R30, (31*8)(R3)
   963  	MOVV    R31, (32*8)(R3)
   964  
   965  	// Perform a safe-point check.
   966  	MOVV    R1, 8(R3)
   967  	CALL    runtime·debugCallCheck(SB)
   968  	MOVV    16(R3), R30
   969  	BEQ R30, good
   970  
   971  	// The safety check failed. Put the reason string at the top
   972  	// of the stack.
   973  	MOVV    R30, 8(R3)
   974  
   975  	MOVV    24(R3), R30
   976  	MOVV    R30, 16(R3)
   977  
   978  	MOVV    $8, R19
   979  	BREAK
   980  	JMP restore
   981  
   982  good:
   983  	// Registers are saved and it's safe to make a call.
   984  	// Open up a call frame, moving the stack if necessary.
   985  	//
   986  	// Once the frame is allocated, this will set R19 to 0 and
   987  	// invoke BREAK. The debugger should write the argument
   988  	// frame for the call at SP+8, set up argument registers,
   989  	// set the LR as the signal PC + 4, set the PC to the function
   990  	// to call, set R29 to point to the closure (if a closure call),
   991  	// and resume execution.
   992  	//
   993  	// If the function returns, this will set R19 to 1 and invoke
   994  	// BREAK. The debugger can then inspect any return value saved
   995  	// on the stack at SP+8 and in registers. To resume execution,
   996  	// the debugger should restore the LR from (SP).
   997  	//
   998  	// If the function panics, this will set R19 to 2 and invoke BREAK.
   999  	// The interface{} value of the panic will be at SP+8. The debugger
  1000  	// can inspect the panic value and resume execution again.
  1001  #define DEBUG_CALL_DISPATCH(NAME,MAXSIZE)	\
  1002  	MOVV    $MAXSIZE, R27;         \
  1003  	BLT R27, R30, 5(PC);            \
  1004  	MOVV    $NAME(SB), R28;			\
  1005  	MOVV    R28, 8(R3);			\
  1006  	CALL    runtime·debugCallWrap(SB);	\
  1007  	JMP restore
  1008  
  1009  	MOVV    264(R3), R30 // the argument frame size
  1010  	DEBUG_CALL_DISPATCH(debugCall32<>, 32)
  1011  	DEBUG_CALL_DISPATCH(debugCall64<>, 64)
  1012  	DEBUG_CALL_DISPATCH(debugCall128<>, 128)
  1013  	DEBUG_CALL_DISPATCH(debugCall256<>, 256)
  1014  	DEBUG_CALL_DISPATCH(debugCall512<>, 512)
  1015  	DEBUG_CALL_DISPATCH(debugCall1024<>, 1024)
  1016  	DEBUG_CALL_DISPATCH(debugCall2048<>, 2048)
  1017  	DEBUG_CALL_DISPATCH(debugCall4096<>, 4096)
  1018  	DEBUG_CALL_DISPATCH(debugCall8192<>, 8192)
  1019  	DEBUG_CALL_DISPATCH(debugCall16384<>, 16384)
  1020  	DEBUG_CALL_DISPATCH(debugCall32768<>, 32768)
  1021  	DEBUG_CALL_DISPATCH(debugCall65536<>, 65536)
  1022  	// The frame size is too large. Report the error.
  1023  	MOVV    $debugCallFrameTooLarge<>(SB), R30
  1024  	MOVV    R30, 8(R3)
  1025  	MOVV    $20, R30
  1026  	MOVV    R30, 16(R3) // length of debugCallFrameTooLarge string
  1027  	MOVV    $8, R19
  1028  	BREAK
  1029  	JMP restore
  1030  
  1031  restore:
  1032  	// Calls and failures resume here.
  1033  	//
  1034  	// Set R19 to 16 and invoke BREAK. The debugger should restore
  1035  	// all registers except for PC and SP and resume execution.
  1036  	MOVV    $16, R19
  1037  	BREAK
  1038  	// We must not modify flags after this point.
  1039  
  1040  	// Restore pointer-containing registers, which may have been
  1041  	// modified from the debugger's copy by stack copying.
  1042  	MOVV    (4*8)(R3), R2
  1043  	MOVV    (5*8)(R3), R4
  1044  	MOVV    (6*8)(R3), R5
  1045  	MOVV    (7*8)(R3), R6
  1046  	MOVV    (8*8)(R3), R7
  1047  	MOVV    (9*8)(R3), R8
  1048  	MOVV    (10*8)(R3), R9
  1049  	MOVV    (11*8)(R3), R10
  1050  	MOVV    (12*8)(R3), R11
  1051  	MOVV    (13*8)(R3), R12
  1052  	MOVV    (14*8)(R3), R13
  1053  	MOVV    (15*8)(R3), R14
  1054  	MOVV    (16*8)(R3), R15
  1055  	MOVV    (17*8)(R3), R16
  1056  	MOVV    (18*8)(R3), R17
  1057  	MOVV    (19*8)(R3), R18
  1058  	MOVV    (20*8)(R3), R19
  1059  	MOVV    (21*8)(R3), R20
  1060  	MOVV    (22*8)(R3), R21
  1061  	MOVV    (23*8)(R3), g
  1062  	MOVV    (24*8)(R3), R23
  1063  	MOVV    (25*8)(R3), R24
  1064  	MOVV    (26*8)(R3), R25
  1065  	MOVV    (27*8)(R3), R26
  1066  	MOVV    (28*8)(R3), R27
  1067  	MOVV    (29*8)(R3), R28
  1068  	MOVV    (30*8)(R3), R29
  1069  	MOVV    (31*8)(R3), R30
  1070  	MOVV    (32*8)(R3), R31
  1071  
  1072  	MOVV    0(R3), R30
  1073  	ADDV    $280, R3 // Add 8 more bytes, see saveSigContext
  1074  	MOVV    -8(R3), R1
  1075  	JMP (R30)
  1076  
  1077  // runtime.debugCallCheck assumes that functions defined with the
  1078  // DEBUG_CALL_FN macro are safe points to inject calls.
  1079  #define DEBUG_CALL_FN(NAME,MAXSIZE)		\
  1080  TEXT NAME(SB),WRAPPER,$MAXSIZE-0;		\
  1081  	NO_LOCAL_POINTERS;		\
  1082  	MOVV    $0, R19;		\
  1083  	BREAK;		\
  1084  	MOVV    $1, R19;		\
  1085  	BREAK;		\
  1086  	RET
  1087  DEBUG_CALL_FN(debugCall32<>, 32)
  1088  DEBUG_CALL_FN(debugCall64<>, 64)
  1089  DEBUG_CALL_FN(debugCall128<>, 128)
  1090  DEBUG_CALL_FN(debugCall256<>, 256)
  1091  DEBUG_CALL_FN(debugCall512<>, 512)
  1092  DEBUG_CALL_FN(debugCall1024<>, 1024)
  1093  DEBUG_CALL_FN(debugCall2048<>, 2048)
  1094  DEBUG_CALL_FN(debugCall4096<>, 4096)
  1095  DEBUG_CALL_FN(debugCall8192<>, 8192)
  1096  DEBUG_CALL_FN(debugCall16384<>, 16384)
  1097  DEBUG_CALL_FN(debugCall32768<>, 32768)
  1098  DEBUG_CALL_FN(debugCall65536<>, 65536)
  1099  
  1100  // func debugCallPanicked(val interface{})
  1101  TEXT runtime·debugCallPanicked(SB),NOSPLIT,$16-16
  1102  	// Copy the panic value to the top of stack at SP+8.
  1103  	MOVV    val_type+0(FP), R30
  1104  	MOVV    R30, 8(R3)
  1105  	MOVV    val_data+8(FP), R30
  1106  	MOVV    R30, 16(R3)
  1107  	MOVV    $2, R19
  1108  	BREAK
  1109  	RET
  1110  
  1111  // Note: these functions use a special calling convention to save generated code space.
  1112  // Arguments are passed in registers, but the space for those arguments are allocated
  1113  // in the caller's stack frame. These stubs write the args into that stack space and
  1114  // then tail call to the corresponding runtime handler.
  1115  // The tail call makes these stubs disappear in backtraces.
  1116  TEXT runtime·panicIndex<ABIInternal>(SB),NOSPLIT,$0-16
  1117  	MOVV	R20, R4
  1118  	MOVV	R21, R5
  1119  	JMP	runtime·goPanicIndex<ABIInternal>(SB)
  1120  TEXT runtime·panicIndexU<ABIInternal>(SB),NOSPLIT,$0-16
  1121  	MOVV	R20, R4
  1122  	MOVV	R21, R5
  1123  	JMP	runtime·goPanicIndexU<ABIInternal>(SB)
  1124  TEXT runtime·panicSliceAlen<ABIInternal>(SB),NOSPLIT,$0-16
  1125  	MOVV	R21, R4
  1126  	MOVV	R23, R5
  1127  	JMP	runtime·goPanicSliceAlen<ABIInternal>(SB)
  1128  TEXT runtime·panicSliceAlenU<ABIInternal>(SB),NOSPLIT,$0-16
  1129  	MOVV	R21, R4
  1130  	MOVV	R23, R5
  1131  	JMP	runtime·goPanicSliceAlenU<ABIInternal>(SB)
  1132  TEXT runtime·panicSliceAcap<ABIInternal>(SB),NOSPLIT,$0-16
  1133  	MOVV	R21, R4
  1134  	MOVV	R23, R5
  1135  	JMP	runtime·goPanicSliceAcap<ABIInternal>(SB)
  1136  TEXT runtime·panicSliceAcapU<ABIInternal>(SB),NOSPLIT,$0-16
  1137  	MOVV	R21, R4
  1138  	MOVV	R23, R5
  1139  	JMP	runtime·goPanicSliceAcapU<ABIInternal>(SB)
  1140  TEXT runtime·panicSliceB<ABIInternal>(SB),NOSPLIT,$0-16
  1141  	MOVV	R20, R4
  1142  	MOVV	R21, R5
  1143  	JMP	runtime·goPanicSliceB<ABIInternal>(SB)
  1144  TEXT runtime·panicSliceBU<ABIInternal>(SB),NOSPLIT,$0-16
  1145  	MOVV	R20, R4
  1146  	MOVV	R21, R5
  1147  	JMP	runtime·goPanicSliceBU<ABIInternal>(SB)
  1148  TEXT runtime·panicSlice3Alen<ABIInternal>(SB),NOSPLIT,$0-16
  1149  	MOVV	R23, R4
  1150  	MOVV	R24, R5
  1151  	JMP	runtime·goPanicSlice3Alen<ABIInternal>(SB)
  1152  TEXT runtime·panicSlice3AlenU<ABIInternal>(SB),NOSPLIT,$0-16
  1153  	MOVV	R23, R4
  1154  	MOVV	R24, R5
  1155  	JMP	runtime·goPanicSlice3AlenU<ABIInternal>(SB)
  1156  TEXT runtime·panicSlice3Acap<ABIInternal>(SB),NOSPLIT,$0-16
  1157  	MOVV	R23, R4
  1158  	MOVV	R24, R5
  1159  	JMP	runtime·goPanicSlice3Acap<ABIInternal>(SB)
  1160  TEXT runtime·panicSlice3AcapU<ABIInternal>(SB),NOSPLIT,$0-16
  1161  	MOVV	R23, R4
  1162  	MOVV	R24, R5
  1163  	JMP	runtime·goPanicSlice3AcapU<ABIInternal>(SB)
  1164  TEXT runtime·panicSlice3B<ABIInternal>(SB),NOSPLIT,$0-16
  1165  	MOVV	R21, R4
  1166  	MOVV	R23, R5
  1167  	JMP	runtime·goPanicSlice3B<ABIInternal>(SB)
  1168  TEXT runtime·panicSlice3BU<ABIInternal>(SB),NOSPLIT,$0-16
  1169  	MOVV	R21, R4
  1170  	MOVV	R23, R5
  1171  	JMP	runtime·goPanicSlice3BU<ABIInternal>(SB)
  1172  TEXT runtime·panicSlice3C<ABIInternal>(SB),NOSPLIT,$0-16
  1173  	MOVV	R20, R4
  1174  	MOVV	R21, R5
  1175  	JMP	runtime·goPanicSlice3C<ABIInternal>(SB)
  1176  TEXT runtime·panicSlice3CU<ABIInternal>(SB),NOSPLIT,$0-16
  1177  	MOVV	R20, R4
  1178  	MOVV	R21, R5
  1179  	JMP	runtime·goPanicSlice3CU<ABIInternal>(SB)
  1180  TEXT runtime·panicSliceConvert<ABIInternal>(SB),NOSPLIT,$0-16
  1181  	MOVV	R23, R4
  1182  	MOVV	R24, R5
  1183  	JMP	runtime·goPanicSliceConvert<ABIInternal>(SB)
  1184  

View as plain text