aboutsummaryrefslogtreecommitdiff
path: root/model/riscv_vmem_common.sail
blob: d17cb02454138fbc13a63a353b8f9b9520d2a6e6 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*=======================================================================================*/
/*  This Sail RISC-V architecture model, comprising all files and                        */
/*  directories except where otherwise noted is subject the BSD                          */
/*  two-clause license in the LICENSE file.                                              */
/*                                                                                       */
/*  SPDX-License-Identifier: BSD-2-Clause                                                */
/*=======================================================================================*/

// ****************************************************************
// Parameters for VM modes sv32, sv39, sv48 and (TODO) Sv57

// All VM modes use the same page size (4KB, with 12-bit index)

// This two-line idiom constrains the value (2nd line) to be a singleton,
// which helps in type-checking wherever it is used.
type PAGESIZE_BITS : Int = 12
let  pagesize_bits = sizeof(PAGESIZE_BITS)

// PRIVATE
struct SV_Params = {
  // VA
  va_size_bits        : {32, 39, 48},    //   32    39    48
  vpn_size_bits       : {10,  9},        //   10     9     9

  // PTE
  levels              : { 2,  3,  4},    //    2     3     4
  log_pte_size_bytes  : { 2,  3},        //    2     3     3
  pte_msbs_lsb_index  : {32, 54},        //   32    54    54
  pte_msbs_size_bits  : { 0, 10},        //    0    10    10
  pte_PPNs_lsb_index  : {10},            //   10    10    10
  pte_PPNs_size_bits  : {22, 44},        //   22    44    44
  pte_PPN_j_size_bits : {10,  9}         //   10     9     9
}

// Current level during a page-table walk (0 to SV_Params.levels - 1)
type PTW_Level = range(0,3)    // range(0,4) when add Sv57 (TODO)

// PRIVATE
let sv32_params : SV_Params = struct {
       // VA
       va_size_bits        = 32,
       vpn_size_bits       = 10,

       // PTE
       levels              = 2,
       log_pte_size_bytes  = 2,    // 4 Bytes
       pte_msbs_lsb_index  = 32,
       pte_msbs_size_bits  = 0,
       pte_PPNs_lsb_index  = 10,
       pte_PPNs_size_bits  = 22,
       pte_PPN_j_size_bits = 10
}

// PRIVATE
let sv39_params : SV_Params = struct {
       // VA
       va_size_bits        = 39,
       vpn_size_bits       = 9,

       // PTE
       levels              = 3,
       log_pte_size_bytes  = 3,    // 8 Bytes
       pte_msbs_lsb_index  = 54,
       pte_msbs_size_bits  = 10,
       pte_PPNs_lsb_index  = 10,
       pte_PPNs_size_bits  = 44,
       pte_PPN_j_size_bits = 9
}

// PRIVATE
let sv48_params : SV_Params = struct {
       // VA
       va_size_bits        = 48,
       vpn_size_bits       = 9,

       // PTE
       levels              = 4,
       log_pte_size_bytes  = 3,    // 8 Bytes
       pte_msbs_lsb_index  = 54,
       pte_msbs_size_bits  = 10,
       pte_PPNs_lsb_index  = 10,
       pte_PPNs_size_bits  = 44,
       pte_PPN_j_size_bits = 9
}

// TODO; not currently used
// PRIVATE
/*
let sv57_params : SV_Params = struct {
       // VA
       va_size_bits        = 57,
       vpn_size_bits       = 9,

       // PTE
       levels              = 5,
       log_pte_size_bytes  = 3,    // 8 Bytes
       pte_msbs_lsb_index  = 54,
       pte_msbs_size_bits  = 10,
       pte_PPNs_lsb_index  = 10,
       pte_PPNs_size_bits  = 44,
       pte_PPN_j_size_bits = 9
}
*/

// This 'undefined_SV_Params()' function is not used anywhere, but is
// currently (2023-12) needed to work around an issue where Sail tries
// to figure out how it could do
//     let x : SV_Params = undefined
// even though the code never does this.  This has been fixed in Sail.
// The fix will become available in a new Sail release, at which point
// this function can be deleted (TODO).
// PRIVATE
val      undefined_SV_Params : unit -> SV_Params
function undefined_SV_Params() = sv32_params