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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2009 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 arm
     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 R8, and returns a pointer
    16  // to the buffer space in R8.
    17  // It clobbers condition codes.
    18  // It does not clobber any other general-purpose registers,
    19  // but may clobber others (e.g., floating point registers).
    20  // The act of CALLing gcWriteBarrier will clobber R14 (LR).
    21  TEXT gcWriteBarrier<>(SB),NOSPLIT|NOFRAME,$0
    22  	// Save the registers clobbered by the fast path.
    23  	MOVM.DB.W [R0,R1], (R13)
    24  retry:
    25  	MOVW g_m(g), R0
    26  	MOVW m_p(R0), R0
    27  	MOVW (p_wbBuf+wbBuf_next)(R0), R1
    28  	MOVW (p_wbBuf+wbBuf_end)(R0), R11
    29  	// Increment wbBuf.next position.
    30  	ADD R8, R1
    31  	// Is the buffer full?
    32  	CMP R11, R1
    33  	BHI flush
    34  	// Commit to the larger buffer.
    35  	MOVW R1, (p_wbBuf+wbBuf_next)(R0)
    36  	// Make return value (the original next position)
    37  	SUB R8, R1, R8
    38  	// Restore registers.
    39  	MOVM.IA.W (R13), [R0,R1]
    40  	RET
    41  
    42  flush:
    43  	// Save all general purpose registers since these could be
    44  	// clobbered by wbBufFlush and were not saved by the caller.
    45  	//
    46  	// R0 and R1 were saved at entry.
    47  	// R10 is g, so preserved.
    48  	// R11 is linker temp, so no need to save.
    49  	// R13 is stack pointer.
    50  	// R15 is PC.
    51  	MOVM.DB.W [R2-R9,R12], (R13)
    52  	// Save R14 (LR) because the fast path above doesn't save it,
    53  	// but needs it to RET.
    54  	MOVM.DB.W [R14], (R13)
    55  
    56  	CALL runtime·wbBufFlush(SB)
    57  
    58  	MOVM.IA.W (R13), [R14]
    59  	MOVM.IA.W (R13), [R2-R9,R12]
    60  	JMP retry
    61  
    62  TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0
    63  	MOVW $4, R8
    64  	JMP gcWriteBarrier<>(SB)
    65  TEXT runtime·gcWriteBarrier2<ABIInternal>(SB),NOSPLIT,$0
    66  	MOVW $8, R8
    67  	JMP gcWriteBarrier<>(SB)
    68  TEXT runtime·gcWriteBarrier3<ABIInternal>(SB),NOSPLIT,$0
    69  	MOVW $12, R8
    70  	JMP gcWriteBarrier<>(SB)
    71  TEXT runtime·gcWriteBarrier4<ABIInternal>(SB),NOSPLIT,$0
    72  	MOVW $16, R8
    73  	JMP gcWriteBarrier<>(SB)
    74  TEXT runtime·gcWriteBarrier5<ABIInternal>(SB),NOSPLIT,$0
    75  	MOVW $20, R8
    76  	JMP gcWriteBarrier<>(SB)
    77  TEXT runtime·gcWriteBarrier6<ABIInternal>(SB),NOSPLIT,$0
    78  	MOVW $24, R8
    79  	JMP gcWriteBarrier<>(SB)
    80  TEXT runtime·gcWriteBarrier7<ABIInternal>(SB),NOSPLIT,$0
    81  	MOVW $28, R8
    82  	JMP gcWriteBarrier<>(SB)
    83  TEXT runtime·gcWriteBarrier8<ABIInternal>(SB),NOSPLIT,$0
    84  	MOVW $32, R8
    85  	JMP gcWriteBarrier<>(SB)