summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseLib/LoongArch64/Csr.c
blob: 5a40bfede5a3a836f359186238e97f49f94f5211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/** @file
  LoongArch CSR operation functions.

  Copyright (c) 2024, Loongson Technology Corporation Limited. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent
**/

UINTN
AsmCsrRead (
  IN UINT16  Select
  );

UINTN
AsmCsrWrite (
  IN UINT16  Select,
  IN UINTN   Value
  );

UINTN
AsmCsrXChg (
  IN UINT16  Select,
  IN UINTN   Value,
  IN UINTN   Mask
  );

/**
  CSR read operation.

  @param[in]  Select   CSR read instruction select values.

  @return     The return value of csrrd instruction,
              if a break exception is triggered, the Select is out of support.
**/
UINTN
EFIAPI
CsrRead (
  IN UINT16  Select
  )
{
  return AsmCsrRead (Select);
}

/**
  CSR write operation.

  @param[in]       Select  CSR write instruction select values.
  @param[in, out]  Value   The csrwr will write the value.

  @return     The return value of csrwr instruction, that is, store the old value of
              the register, if a break exception is triggered, the Select is out of support.
**/
UINTN
EFIAPI
CsrWrite (
  IN     UINT16  Select,
  IN OUT UINTN   Value
  )
{
  return AsmCsrWrite (Select, Value);
}

/**
  CSR exchange operation.

  @param[in]       Select   CSR exchange instruction select values.
  @param[in, out]  Value    The csrxchg will write the value.
  @param[in]       Mask     The csrxchg mask value.

  @return     The return value of csrxchg instruction, that is, store the old value of
              the register, if a break exception is triggered, the Select is out of support.
**/
UINTN
EFIAPI
CsrXChg (
  IN     UINT16  Select,
  IN OUT UINTN   Value,
  IN     UINTN   Mask
  )
{
  return AsmCsrXChg (Select, Value, Mask);
}