github.com/primecitizens/pcz/std@v0.2.1/core/gc/wb_riscv64.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2017 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build riscv64
     9  
    10  #include "textflag.h"
    11  
    12  // gcWriteBarrier informs the GC about heap pointer writes.
    13  //
    14  // gcWriteBarrier does NOT follow the Go ABI. It accepts the
    15  // number of bytes of buffer needed in X24, and returns a pointer
    16  // to the buffer space in X24.
    17  // It clobbers X31 aka T6 (the linker temp register - REG_TMP).
    18  // The act of CALLing gcWriteBarrier will clobber RA (LR).
    19  // It does not clobber any other general-purpose registers,
    20  // but may clobber others (e.g., floating point registers).
    21  TEXT gcWriteBarrier<>(SB),NOSPLIT,$208
    22  	// Save the registers clobbered by the fast path.
    23  	MOV A0, 24*8(X2)
    24  	MOV A1, 25*8(X2)
    25  retry:
    26  	MOV g_m(g), A0
    27  	MOV m_p(A0), A0
    28  	MOV (p_wbBuf+wbBuf_next)(A0), A1
    29  	MOV (p_wbBuf+wbBuf_end)(A0), T6 // T6 is linker temp register (REG_TMP)
    30  	// Increment wbBuf.next position.
    31  	ADD X24, A1
    32  	// Is the buffer full?
    33  	BLTU T6, A1, flush
    34  	// Commit to the larger buffer.
    35  	MOV A1, (p_wbBuf+wbBuf_next)(A0)
    36  	// Make the return value (the original next position)
    37  	SUB X24, A1, X24
    38  	// Restore registers.
    39  	MOV 24*8(X2), A0
    40  	MOV 25*8(X2), A1
    41  	RET
    42  
    43  flush:
    44  	// Save all general purpose registers since these could be
    45  	// clobbered by wbBufFlush and were not saved by the caller.
    46  	MOV T0, 1*8(X2)
    47  	MOV T1, 2*8(X2)
    48  	// X0 is zero register
    49  	// X1 is LR, saved by prologue
    50  	// X2 is SP
    51  	// X3 is GP
    52  	// X4 is TP
    53  	MOV X7, 3*8(X2)
    54  	MOV X8, 4*8(X2)
    55  	MOV X9, 5*8(X2)
    56  	// X10 already saved (A0)
    57  	// X11 already saved (A1)
    58  	MOV X12, 6*8(X2)
    59  	MOV X13, 7*8(X2)
    60  	MOV X14, 8*8(X2)
    61  	MOV X15, 9*8(X2)
    62  	MOV X16, 10*8(X2)
    63  	MOV X17, 11*8(X2)
    64  	MOV X18, 12*8(X2)
    65  	MOV X19, 13*8(X2)
    66  	MOV X20, 14*8(X2)
    67  	MOV X21, 15*8(X2)
    68  	MOV X22, 16*8(X2)
    69  	MOV X23, 17*8(X2)
    70  	MOV X24, 18*8(X2)
    71  	MOV X25, 19*8(X2)
    72  	MOV X26, 20*8(X2)
    73  	// X27 is g.
    74  	MOV X28, 21*8(X2)
    75  	MOV X29, 22*8(X2)
    76  	MOV X30, 23*8(X2)
    77  	// X31 is tmp register.
    78  
    79  	CALL runtime·wbBufFlush(SB)
    80  
    81  	MOV 1*8(X2), T0
    82  	MOV 2*8(X2), T1
    83  	MOV 3*8(X2), X7
    84  	MOV 4*8(X2), X8
    85  	MOV 5*8(X2), X9
    86  	MOV 6*8(X2), X12
    87  	MOV 7*8(X2), X13
    88  	MOV 8*8(X2), X14
    89  	MOV 9*8(X2), X15
    90  	MOV 10*8(X2), X16
    91  	MOV 11*8(X2), X17
    92  	MOV 12*8(X2), X18
    93  	MOV 13*8(X2), X19
    94  	MOV 14*8(X2), X20
    95  	MOV 15*8(X2), X21
    96  	MOV 16*8(X2), X22
    97  	MOV 17*8(X2), X23
    98  	MOV 18*8(X2), X24
    99  	MOV 19*8(X2), X25
   100  	MOV 20*8(X2), X26
   101  	MOV 21*8(X2), X28
   102  	MOV 22*8(X2), X29
   103  	MOV 23*8(X2), X30
   104  
   105  	JMP retry
   106  
   107  TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0
   108  	MOV $8, X24
   109  	JMP gcWriteBarrier<>(SB)
   110  TEXT runtime·gcWriteBarrier2<ABIInternal>(SB),NOSPLIT,$0
   111  	MOV $16, X24
   112  	JMP gcWriteBarrier<>(SB)
   113  TEXT runtime·gcWriteBarrier3<ABIInternal>(SB),NOSPLIT,$0
   114  	MOV $24, X24
   115  	JMP gcWriteBarrier<>(SB)
   116  TEXT runtime·gcWriteBarrier4<ABIInternal>(SB),NOSPLIT,$0
   117  	MOV $32, X24
   118  	JMP gcWriteBarrier<>(SB)
   119  TEXT runtime·gcWriteBarrier5<ABIInternal>(SB),NOSPLIT,$0
   120  	MOV $40, X24
   121  	JMP gcWriteBarrier<>(SB)
   122  TEXT runtime·gcWriteBarrier6<ABIInternal>(SB),NOSPLIT,$0
   123  	MOV $48, X24
   124  	JMP gcWriteBarrier<>(SB)
   125  TEXT runtime·gcWriteBarrier7<ABIInternal>(SB),NOSPLIT,$0
   126  	MOV $56, X24
   127  	JMP gcWriteBarrier<>(SB)
   128  TEXT runtime·gcWriteBarrier8<ABIInternal>(SB),NOSPLIT,$0
   129  	MOV $64, X24
   130  	JMP gcWriteBarrier<>(SB)