github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/riscv/pmp.s (about)

     1  // RISC-V processor support
     2  // https://github.com/usbarmory/tamago
     3  //
     4  // Copyright (c) WithSecure Corporation
     5  // https://foundry.withsecure.com
     6  //
     7  // Use of this source code is governed by the license
     8  // that can be found in the LICENSE file.
     9  
    10  // PMP CSRs helpers for RV64, only 8 PMPs are supported for now. In the future,
    11  // to support up to 64 PMPs, this will benefit from dynamic generation with
    12  // go:generate.
    13  
    14  #include "csr.h"
    15  
    16  #define pmpcfg0  0x3a0
    17  #define pmpaddr0 0x3b0
    18  #define pmpaddr1 0x3b1
    19  #define pmpaddr2 0x3b2
    20  #define pmpaddr3 0x3b3
    21  #define pmpaddr4 0x3b4
    22  #define pmpaddr5 0x3b5
    23  #define pmpaddr6 0x3b6
    24  #define pmpaddr7 0x3b7
    25  #define pmpaddr8 0x3b8
    26  
    27  // func read_pmpcfg0() uint64
    28  TEXT ·read_pmpcfg0(SB),$0-8
    29  	// Volume II: RISC-V Privileged Architectures V20211203
    30  	// 3.7.1 Physical Memory Protection CSRs
    31  	CSRR	(pmpcfg0, t0)
    32  	MOV	T0, ret+0(FP)
    33  
    34  	RET
    35  
    36  // func write_pmpcfg0(uint64)
    37  TEXT ·write_pmpcfg0(SB),$0-8
    38  	// Volume II: RISC-V Privileged Architectures V20211203
    39  	// 3.7.1 Physical Memory Protection CSRs
    40  	MOV	cfg+0(FP), T0
    41  	CSRW	(t0, pmpcfg0)
    42  
    43  	RET
    44  
    45  // func read_pmpaddr0() uint64
    46  TEXT ·read_pmpaddr0(SB),$0-8
    47  	CSRR	(pmpaddr0, t0)
    48  	MOV	T0, ret+0(FP)
    49  	RET
    50  
    51  // func read_pmpaddr1() uint64
    52  TEXT ·read_pmpaddr1(SB),$0-8
    53  	CSRR	(pmpaddr1, t0)
    54  	MOV	T0, ret+0(FP)
    55  	RET
    56  
    57  // func read_pmpaddr2() uint64
    58  TEXT ·read_pmpaddr2(SB),$0-8
    59  	CSRR	(pmpaddr2, t0)
    60  	MOV	T0, ret+0(FP)
    61  	RET
    62  
    63  // func read_pmpaddr3() uint64
    64  TEXT ·read_pmpaddr3(SB),$0-8
    65  	CSRR	(pmpaddr3, t0)
    66  	MOV	T0, ret+0(FP)
    67  	RET
    68  
    69  // func read_pmpaddr4() uint64
    70  TEXT ·read_pmpaddr4(SB),$0-8
    71  	CSRR	(pmpaddr4, t0)
    72  	MOV	T0, ret+0(FP)
    73  	RET
    74  
    75  // func read_pmpaddr5() uint64
    76  TEXT ·read_pmpaddr5(SB),$0-8
    77  	CSRR	(pmpaddr5, t0)
    78  	MOV	T0, ret+0(FP)
    79  	RET
    80  
    81  // func read_pmpaddr6() uint64
    82  TEXT ·read_pmpaddr6(SB),$0-8
    83  	CSRR	(pmpaddr6, t0)
    84  	MOV	T0, ret+0(FP)
    85  	RET
    86  
    87  // func read_pmpaddr7() uint64
    88  TEXT ·read_pmpaddr7(SB),$0-8
    89  	CSRR	(pmpaddr7, t0)
    90  	MOV	T0, ret+0(FP)
    91  	RET
    92  
    93  // func write_pmpaddr0(uint64)
    94  TEXT ·write_pmpaddr0(SB),$0-8
    95  	MOV	addr+0(FP), T0
    96  	CSRW	(t0, pmpaddr0)
    97  	RET
    98  
    99  // func write_pmpaddr1(uint64)
   100  TEXT ·write_pmpaddr1(SB),$0-8
   101  	MOV	addr+0(FP), T0
   102  	CSRW	(t0, pmpaddr1)
   103  	RET
   104  
   105  // func write_pmpaddr2(uint64)
   106  TEXT ·write_pmpaddr2(SB),$0-8
   107  	MOV	addr+0(FP), T0
   108  	CSRW	(t0, pmpaddr2)
   109  	RET
   110  
   111  // func write_pmpaddr3(uint64)
   112  TEXT ·write_pmpaddr3(SB),$0-8
   113  	MOV	addr+0(FP), T0
   114  	CSRW	(t0, pmpaddr3)
   115  	RET
   116  
   117  // func write_pmpaddr4(uint64)
   118  TEXT ·write_pmpaddr4(SB),$0-8
   119  	MOV	addr+0(FP), T0
   120  	CSRW	(t0, pmpaddr4)
   121  	RET
   122  
   123  // func write_pmpaddr5(uint64)
   124  TEXT ·write_pmpaddr5(SB),$0-8
   125  	MOV	addr+0(FP), T0
   126  	CSRW	(t0, pmpaddr5)
   127  	RET
   128  
   129  // func write_pmpaddr6(uint64)
   130  TEXT ·write_pmpaddr6(SB),$0-8
   131  	MOV	addr+0(FP), T0
   132  	CSRW	(t0, pmpaddr6)
   133  	RET
   134  
   135  // func write_pmpaddr7(uint64)
   136  TEXT ·write_pmpaddr7(SB),$0-8
   137  	MOV	addr+0(FP), T0
   138  	CSRW	(t0, pmpaddr7)
   139  	RET